Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [zsh]

Zsh is a shell with many advanced command-line and scripting features.

2
votes
1answer
18 views

Using heredoc in zsh aliases

I would like to use heredoc in a zsh alias, for example: alias runthing="cd ~; date << HERE date HERE" However every time I run this alias, the shell acts as if I have not terminated the ...
1
vote
0answers
18 views

Display `time` of process periodically

A week ago I launched simulations in the following way: make rebuild; time make run with the time command intended to record the CPU times used in each case. A week later the simulations finished ...
2
votes
2answers
30 views

Remove zsh autocomplete suggestion

When I type cd l and hit tab, zsh autocompletes to cd lightdm/ this is not a directory that is available to me (in fact I've uninstalled lightdm). How do I stop this from happening? I have ...
0
votes
2answers
26 views

Zsh: change color of vared -p command

I tried: vared -p '"$(print \"\e[1;31test\")" something' -c tmp Output echo "$(print \"\e[1;31test\")" something But I want to change color of test word here. Howto achieve?
0
votes
1answer
33 views

Catch result of sub-process in Z-shell

AAA <options>; CCC AAA <options> AAA, CCC are different commands. Here we're in an zsh script - for example: vi script.zsh <...> AAA <options>; CCC AAA <options> <.....
0
votes
1answer
34 views

Zsh: test newline in case

# user input a here vared -p "input something" -c a case $a { ([y|'\n']) echo something;; } won't work, can someone give an insight? I'm trying to test against user input that if contain y or an ...
0
votes
1answer
27 views

How to use aliases with auto completion in oh-my-zsh?

I'm using zsh on MacOS El Capitan. I'm wondering how auto completion has to be parameterized to resolve aliases as well. When I used bash, my .bash_profile contained the following: alias mdb "mongo -...
0
votes
1answer
22 views

Zsh: Put all non-global parameters to anonymous/local inner function

Correct me if this statement is wrong: All variables/parameters that defined inside a zsh script keep its persistent scope globally in current shell session. If above statement is true, then to avoid ...
2
votes
1answer
22 views

Rerun previous command immediately in zsh instead of creating it

I know I can re-run a previous command using !!, but doing this in zshell only grabs the command and puts in on the new line, which requires me to press enter again to execute it. For example: ~ ...
1
vote
1answer
50 views

Examples of Zsh alternate forms of complex commands

Would you please provide an insight on this portion of the zsh documentation. I spent a very long time on this document but could bot make it clear: http://zsh.sourceforge.net/Doc/Release/Shell-...
0
votes
1answer
53 views

Why doesn't var=- work?

In writing the question: How to touch and cat file named - I was trying to generalise to a case where a file named - was stored in a variable. In zsh, I tried setting a variable to contain a single ...
2
votes
1answer
52 views

Wildcard expansion zsh

I'm running on a server where qstat gives me the IDs of running jobs (details not important). E.g., say I have three jobs running, 123, 124, 125, then > qstat 123 124 125 Each job has a log file ...
0
votes
1answer
51 views

How do I get rid of underline when typing commands in zsh?

I use zsh with oh-my-zsh and it almost suits my needs. However, there is one thing I cannot figure out, namely how do I get rid of an underline of some parts of commands I type? Please have a look at ...
1
vote
2answers
20 views

tmux can't see nested session

Extent of this question: https://unix.stackexchange.com/q/467025/256195 But now after run tmux inside sessionA to create sessionB, actually first tmux create a new named session 1 and I'd need to ...
0
votes
3answers
29 views

Switch between nested tmux sessions

I'm writing a zsh script that setup nested session. I have a session and a session inside that session. sessionA sessionB I can create sessionA in detach mode -d and then call tmux inside that to ...
3
votes
2answers
39 views

zsh script that takes a variable number of arguments

I have just (belatedly) discovered that I can ssh -t from one machine to another and run a command there. The thought then took me that I should be able to come up with a script that tailed a log ...
0
votes
0answers
17 views

Track what set zsh option

Currently I have noautomenu on but search through entire homeuser I seem can't find any line that set this option, rg --hidden noautomenu . that make me believe some plugin or scripts set it ...
1
vote
0answers
20 views

Track what zsh-plugins create .zcompdump file under homeuser

I have this line in .zshrc that instructs zsh to create .zcompdump file under ~/.cache/zsh/ but I believe a zsh plugin created it somehow under homeuser: autoload -Uz compinit ...
1
vote
1answer
22 views

/home/user/.zshenv:5: command not found: rustc

Error as title: /home/sugar/.zshenv:5: command not found: rustc I installed rust with modify path: y and checked with print $path and observed /home/user/.cargo/bin in first elemnt of $path array. So ...
7
votes
2answers
357 views

Why [[ -n $var ]] instead of [[ $var ]]?

In this answer I had some code which read: if [[ $ZSH_VERSION ]]; then This was edited to be: if [[ -n $ZSH_VERSION ]]; then Update: I just saw the edit comment: [[ x ]] didn't work until ...
2
votes
2answers
35 views

Alternative of bash's `history -p` in zsh?

In bash, history -p does history expansion on its argument; What is the alternative in zsh?
3
votes
1answer
30 views

How can I alias a history expansion in zsh?

I want this to work (it needs extendedglob and histsubstpattern): alias ri='^(#b)E(?)^E${(l:2::0:)$((match[1]+1))}' But it doesn't: $ alias sss='^(#b)E(?)^E${(l:2::0:)$((match[1]+1))}' ...
1
vote
1answer
26 views

How can I increase a number found by wildcard in the previous command? (zsh)

I want to accomplish this: setopt HIST_SUBST_PATTERN echo Ninja_Turtles_2003_S02E05_DVDRip_30NAMA.mkv ^E(0?)^E$((match[1]+1)) # resulting in: echo Ninja_Turtles_2003_S02E06_DVDRip_30NAMA.mkv ‌But I ...
2
votes
1answer
20 views

restricting hist_verify in zsh

Is it possible to bypass hist_verify for specific history commands? For instance, I rarely have the need to verify !$ or !!, whereas I find verification to be a useful feature for more complicated ...
0
votes
1answer
23 views

What's the difference between ZSH themes, prompts, and terminal based themes?

I perhaps may have started overthinking this, but I also couldn't find a suitable explanation for it. I recently installed oh-my-zsh and it comes with several themes that change the way the "prompt" ...
0
votes
1answer
11 views

calling two versions of nodejs with different names

I have two version of nodejs installed. One in /users/anaconda/bin/ and another by homebrew Now I want to use both NodeJS versions. I want to use conda version using conda-node and homebrew version ...
0
votes
0answers
15 views

Tmux-logging: zle reset-prompt cause enter in log file

I need real-time clock in prompt so I enable trap with zle reset-prompt, this causing tmux-logging continue to capture like enter with TMOUT=1 - each 1s causing like new line, I have bunch of these ...
1
vote
0answers
34 views

Why should anyone ever put anything in /etc/zshenv or ~/.zshenv? [closed]

There is already a question "What should/shouldn't go in .zshenv, .zshrc, .zlogin, .zprofile, .zlogout?". I'm wondering why anyone ever puts anything in /etc/zshenv or ~/.zshenv. For those who are ...
1
vote
1answer
24 views

Check zsh script's argument against pattern in multiple files and keep tracking of matched pattern for other tasks

This is extended question of Howto check against zsh script's parameter in a pattern or not While the link above solved the problem that a zsh script check agaist its first argument to list of ...
3
votes
2answers
33 views

.zshrc shortcut working on Arch but not Ubuntu

Helllo everyone, I use the zsh shell as default shell on both Ubuntu and Arch. I configured a shortcut (the up arrow) to autocomplete from history in my zsh shell, using the following line in my ....
1
vote
1answer
22 views

Generating nested part of a glob pattern using command substitution

Let's start with a simple filename generation example: echo (xx|yy|zz)*.txt # Example 1 This lists all txt-files starting with xx or yy or zz. Now let's generate those alternatives dynamically ...
0
votes
0answers
24 views

Avoid terminal scroll issue when using zle reset-prompt

I use TMOUT=10 - 10s to update time in prompt so it caused scroll always go back to current prompt. For i.e: If I scroll back serverl pages of output then 10s later, zsh scroll down when prompt was ...
0
votes
1answer
22 views

zsh script testing ssh successfully or not

I have a zsh script script.zsh server-name-here that have one argument, I need to test ssh to that server-name-here, and if success continue doing something, if not exit script. How can we achieve ...
4
votes
4answers
108 views

Is it common to install zsh on production servers? [closed]

Question may be not clear and too broad, but any answer, however short or broad it may be, is very appreciated. Some time ago I've asked to install zsh on our production server. My admins companies ...
1
vote
1answer
35 views

Howto check against zsh script's parameter in a pattern or not

A zsh script that run: script.zsh nameabc01, in script.zsh I need to check against that if nameabc01 is in this pattern na*abc* or not to continue do something or decide to exit script. How can we ...
1
vote
0answers
13 views

Zsh/Tmux: Script find a specific session, setup layout then run commands on panes [closed]

I have tmux session that named ABC, now in tmux session ABC I'd like to run a zsh script that ask me for the name of tmux session, the name of window, how many panes I'd like to create, how many ...
0
votes
1answer
23 views

cat hangs randomly in .zshenv

Here's what I've got in ~/.zshenv (/etc/zshenv is blank) print -P "before %D{%H:%M:%S}" /usr/bin/time /bin/cat /dev/null print -P "after %D{%H:%M:%S}" If I try to start zsh, it will occasionally ...
2
votes
2answers
165 views

How to disable word splitting during command substitution?

How can I disable word-splitting during command substitution? Here's a simplified example of the problem: 4:00PM /Users/paymahn/Downloads ❯❯❯ cat test.txt hello\nworld 4:00PM /Users/paymahn/...
3
votes
1answer
35 views

Replace string in command to be executed in zsh

Say I have written the following command but haven't yet pressed enter to execute it: $ ls dir1 dir2 dir3 Is there a way to replace given characters without manually changing them in every location ...
2
votes
1answer
28 views

Generating quoted command arguments

I'm working with a HTTP API that demands a very particular set of signed headers + JSON body. And I really want to cURL it for debugging and sanity in general. So, I've written a small script that, ...
7
votes
1answer
211 views

My variable's value is 0, but I didn't set it to 0

Today I noticed one of my zsh functions is not functioning; I investigated the issue, and the culprit was this: for i in a b do echo "$i" done 0 0 Then I opened a new zsh, and in that, things were ...
1
vote
4answers
90 views

Get the expansion of an alias (in both bash and zsh)

I want to get the text which an alias expands into. For example, if I have: alias g=hub alias cdh='cd $HOME' I want to have: expand_alias g == hub expand_alias cdh == cd $HOME The tricky thing ...
3
votes
2answers
37 views

Is there a shorter equivalent to long/path/**/^*.(complex|pattern)~long/path/(bad-1|bad-2)/*(.) that doesn't require repeating long/path/?

It's an zsh extended glob pattern. The point is to match all files with a pattern under a directory hierarchy with the exception of specific sub-hierarchies. The pattern in the title works, but I ...
0
votes
2answers
31 views

Spell checking user's input by aspell, but how to invoke the INTERACTIVE mode in this context?

I have wrote a script which receives a user's sentence, i'd like to pipe the string to aspell and then get the INTERACTIVE screen's suggestions (in case user had some typos). Afterwards the words ...
0
votes
3answers
49 views

My MacOSX terminal doesn't show the current directory

No matter what directory I enter, the terminal always shows me the root directory which is "Nidas-MBP" Nidas-MBP% cd Projects Nidas-MBP% ls 09-Selector-Exercise-Starter.zip My Little Form ...
0
votes
1answer
36 views

How to automate a source command

I have to run a command every morning after I log on to the server to enable certain company specific functionalities. The command looks like this: source /data/dev/int/default/somethingsomething.env ...
-1
votes
3answers
57 views

Why is this command working only for every other line?

When I run \ls | xargs -I {} echo {} | sed 'N;s/\n/xxxxxxxxx/', I get this: - Books aliasxxxxxxxxxA New Kind of Science Computability-and-Logic.pdfxxxxxxxxxComputability-and-Logic_k2opt.pdf Hein J. L....
1
vote
2answers
58 views

Splitting a path to a file name [closed]

In my zsh script, I would like to find out, whether my working directory starts with /cygdrive/?/... or matches exactly /cygdrive/? (where the drive letter (?) can be any letter different from the ...
0
votes
0answers
15 views

Can zsh be configured to print all the files it executes or sources at logon time? [duplicate]

Some of the files which are supposed to be run at login time are not working on my system. It appears they are not run at all. Can zsh be configured to print all the files it executes or sources at ...
1
vote
1answer
84 views

Glob character within variable expands in bash but not zsh

I'm seeing an issue with zsh where a glob character within a variable is not expanding as I would expect. The following example does a better job of explaining it. $ echo $0 -bash $ echo $HOME/...