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

learn more… | top users | synonyms (1)

5
votes
1answer
81 views

Do not set $? to non-zero on Control+C

My $PS1 in Zsh includes this expression: %(?. %?.) It means «if exit code of previous command ($?) is true, show $?, else show nothing». This is generally useful, but one thing annoys me: shells set ...
1
vote
1answer
77 views

How can I autocomplete each parameter in a different way?

I have a function called load_pg, which is defined like this: load_pg () { pg_restore --verbose --clean --no-acl --no-owner -h localhost -U $1 -d $2 $3 } And I'm trying to autocomplete each ...
3
votes
3answers
91 views

Is there something like closures for zsh?

I just decided to try zsh (through oh-my-zsh), and am now playing with precmd to emulate a two-line prompt that has right prompts in more than just the last line. So I clone the default theme, and ...
6
votes
3answers
113 views

Excluding . and .. from results in find and ls

Is there any way to prevent find and ls -l from listing . and .. in their results? I never care about seeing this result in the output, and it prevents me from effectively piping their output to wc -l ...
4
votes
3answers
786 views

.ssh/config to start remote session in zsh

I would like to start a remote session without typing the following command ssh user@remoteserverip -t zsh I know that I can change the host names in the ~/.ssh/config to simply use something like ...
11
votes
2answers
120 views

Cancel completion, but only completion, in zsh

When a completion function takes a long time, I can interrupt it by pressing Ctrl+C (terminal interrupt key, sends SIGINT) or Ctrl+G (bound to send-break). I am then left with the uncompleted word. ...
3
votes
2answers
136 views

Asynchronous RPROMPT?

A friend of mine posted this on StackOverflow, and I thought we might be more likely to get an answer here. His post refers to speed, but we now know that the python script we are using to parse git ...
3
votes
1answer
518 views

First characters of the command repeated in the display when completing

The first two chars were repeated while I use Tab to do completion. In the screenshot below, cd is repeated. I have tried rxvt-unicdoe, xterm, terminator. All these terminal emulators have this ...
3
votes
1answer
133 views

“--noprofile” or “--norc” functionality in zsh?

Short and sweet: Is there a way to accomplish what --noprofile and --norc bash switches do using zsh?
3
votes
1answer
190 views

Why is `xargs bash -ic echo` not the same thing as `xargs echo` or `xargs`?

I expect the command ls -d doc/* | grep -P "<some_pattern>" | xargs bash -ic echo to do the same as: ls -d doc/* | grep -P "<some_pattern>" | xargs echo that is, to give me the files ...
3
votes
2answers
57 views

Zsh completion for mounts (/run/media/DISK-LABEL)?

I am looking or zsh functionality to expand disk-labels into mountpoins: Example: I have disk with label DISK-LABEL1 mounted on /run/media/god/DISK-LABEL1. Is there a plugin which expands input ...
3
votes
4answers
1k views

cp hidden files with glob patterns

Situation : $ mkdir foo && touch foo/.test $ cp foo/* . zsh: no matches found: test/* (or bash : cp: cannot stat ‘test/*’: No such file or directory) I have a directory full of hidden ...
1
vote
1answer
115 views

Mysterious repeating of entered command in shell

After booting up my system and logging in (before starting X, I start it manually via startx) I suddenly get the following output after entering a command: $ cmd ;user@host: cmd;cmd;cmd; [output of ...
0
votes
1answer
50 views

Executing a script in .zshrc

I'm trying to use z (link) to make navigating a little easier. The problem is that I have the following in my .zshrc file, but it doesn't seem to work: export PATH=$PATH:/home/x/z alias ...
12
votes
1answer
771 views

How does a fork bomb work?

WARNING DO NOT ATTEMPT TO RUN THIS ON A PRODUCTION MACHINE In reading the Wikipedia page on the topic I generally follow what's going on with the following code: :(){ :|:& };: excerpt of ...
0
votes
0answers
40 views

Write a zsh method the responds to a `cd` command [duplicate]

I'm trying to write a script that will be called when navigating into certain directories. What I'd want is to have a message appear when I enter certain (not every) directories based on what it finds ...
1
vote
2answers
168 views

What is sourcing my shell script?

I have a .zshrc and a .zshenv in my home directory. I added a new command to my .zshenv that I discovered was being run at least 3 times. I realized that I was accidentally sourceing it from the ...
13
votes
2answers
728 views

How to background a command chain?

I want to background a command chain like cp a b && mv b c && rm a. I have tried doing cp a b && mv b c && rm a & but this only backgrounds the last process. How ...
2
votes
2answers
487 views

strange “bad file descriptor” error

I've run into a perplexing error that I'd like to understand better. The problem seems to require the presence of a "wrapper" shell function (as described below), so my immediate interest is to find ...
0
votes
0answers
54 views

Specifying numeric ranges in zsh history

According to the docs I can tell the zsh history to print lines in a range. The docs say "history [first [last]]" I've tried "history a b" but that gives a too many arguments error. I've also tried ...
2
votes
0answers
79 views

Git completions for aliases only available after running `git reflog`

I have a few aliases that I want to autocomplete for git, e.g., the following alias gco="git checkout" When I was attempting to add completions for this alias, I looked around in my path and saw ...
3
votes
1answer
136 views

zsh and COLUMNS

I cannot understand the behavior of the $COLUMNS variable under zsh. Here's an example of the sort of behavior I'm referring to. The script $HOME/cols.sh is the following: echo "COLUMNS=$COLUMNS" ...
3
votes
2answers
150 views

How change prompt of subshell

I'm trying to create a simple script that, among other things, will create a subshell: #!/bin/sh # setup "${@:-$SHELL}" # teardown The question is: I need to change the default prompt, so for ...
4
votes
1answer
2k views

How to display the name of the current Virtualenv?

I'm using virtualenv, virtualenvwrapper, zsh, oh-my-zsh, terminator, on Crunchbang. I'm trying to display the name of the current virtualenv like so workon example (example)... I've tried many ...
2
votes
2answers
103 views

Absolute path to currently-running zsh?

Sometimes the output of ps -p $$ shows the absolute path to the currently-running zsh, % ps -p $$ PID TTY TIME CMD 1027 ttys005 0:00.11 /usr/local/bin/zsh but not always: % ps -p ...
2
votes
2answers
564 views

Zip folder without including path to folder and require only one argument

I'm trying to make a zip function that'll do all the steps I typically do when zipping a file or folder. Say my current directory is ~, and I want to zip a folder named Folder1, whose file path is ...
3
votes
2answers
140 views

bash equivalent of zsh's $@[2,$#]

(NB: the motivation for this question is only to improve my bash programming know-how.) I want to know the bash equivalent of zsh expressions such as $@[2,$#], which directly address a range of a ...
1
vote
2answers
162 views

zsh expand-or-complete for all files regardless of command/context

zsh has a feature where command line tab-completion performs context-aware completions, so you can do things like: # Good: $ wget g<tab> # becomes: $ wget gopher:// $ wget --hea<tab> ...
5
votes
1answer
122 views

can you make zsh autocorrect smarter?

I like zsh autocorrect, but it keeps asking me about things that don't need correcting. dzil build zsh: correct 'build' to '.build' [nyae]? % .build is a directory created by the build (or any ...
5
votes
3answers
364 views

Getting relative links between two paths

Say I have two paths: <source_path> and <target_path>. I would like my shell (zsh) to automatically find out if there is a way to represent <target_path> from <source_path> as ...
3
votes
1answer
243 views

zsh adds tab character when autocompleting

I have zsh 4.3.10 installed on a RHEL 6.4 box. I'm not sure why this happens, but when I but Tab to autocomplete things, it also adds a tab character. For example: rocket@rhelbox www % vim vim ...
4
votes
1answer
245 views

Zsh completion, enabling shift-tab

When zsh shows you a menu of possible completions, I'd like it to let me use shift-tab to access previous completion entries--is there an option that controls what key is used to access previous ...
9
votes
2answers
2k views

Make zsh completion show the first guess on the same line (like fish's)

In Fish when you start typing, autocompletion automatically shows the first autocompleted guess on the line itself. In zsh you have to hit tab, and it shows the autocompletion below. Is there anyway ...
5
votes
1answer
457 views

command substitution handling in fish vs. other shells (sh, bash, zsh)

The program mc (Midnight Commander) is not intended to be used for command substitution, but I would like to know why different shells behave differently when this program (and it seems like other ...
5
votes
3answers
191 views

${#array} vs ${#array[@]}

As far as I can tell both ${#array[@]} and ${#array} evaluate to the number of elements in $array. Is there any reason for preferring the longer form (${#array[@]})?
5
votes
2answers
116 views

Is there a less convoluted way to set the $path array locally within function?

Is there a less laborious way for setting a local version of the $path array than what's shown in the following snippet? foo () { local holdpath holdpath=($path) local path ...
3
votes
2answers
128 views

Refer to an item in `dirs`

I use pushd to work with multiple directories in bash and zsh. I've aliased dirs to dirs -v so that I get an ordered list when I want to see what's on the directory stack: chb$ dirs 0 ...
3
votes
1answer
117 views

How to use parameter substitution in glob pattern (zsh)

I want to process a bunch of files ending in some suffixes, so I wrote the following zsh script but it did not work. EXT=(.jpg .png .gif) EXT=${(j.|.)EXT} # EXT becomes '.jpg|.png|.gif' for f in ...
1
vote
1answer
102 views

How can I use bindkey to run a script?

In the Z shell, how can I use bindkey to bind a key sequence to a script?
5
votes
3answers
257 views

cd to directory of a symbolically linked file

Before I write a script, anyone know an easy way to do the following: $ pwd /foo/bar $ ls -l lrwxr-xr-x 1 username admin 48 Apr 17 2012 foo.sh -> /bar/foo.sh $ cd /bar $ ls foo.sh i.e., in ...
7
votes
1answer
112 views

Change zsh completion to put completions above the prompt

I'm a long-time tcsh user that finally decided to try out zsh. I've been toying around with completion, but one thing I don't like is that when I hit tab for a completion that might have a lot of ...
2
votes
4answers
112 views

$PATH duplication issues

If I do echo $PATH I get the following: ...
5
votes
2answers
2k views

Disk usage summary per user

Is there a way to get the disk usage per user under a given path? du doesn't seem to have an option to aggregate disk usage per user, and df only seems to report how much disk is left on the drive. ...
2
votes
2answers
207 views

Unable to concatenate files with find ./subdir/* -print0 | sort | xargs -0 cat > merge.txt

I am trying to concatenate thousands of files that result from processing the pieces output by split with find ./subdir/* -print0 | sort | xargs -0 cat > full_merge.txt The files under subdir ...
9
votes
2answers
560 views

How do I stop bash from syntax checking sourced files?

I have the following code in a file that is sourced by both zsh and bash. if test $SHELLNAME = zsh ; then lss() { l -l ${1:-.}/*(s,S,t); } laf() { l ${1:-.}/.*(.); } lad() { l -d ...
3
votes
3answers
143 views

Persistent shell arguments

I often find myself running a series of commands on a single set of arguments. For example: $ nmap -Pn -sS 192.168.1.5 $ ssh 192.168.1.5 $ curl 192.168.1.5 $ wget -r 192.168.1.5 This can be sped ...
3
votes
2answers
195 views

Passing quotes and full strings to bash -c or zsh -c

When I am in Perl and I call system(some_command), this invokes some_command on /bin/sh. I would like it instead to run some_command in another shell such as bash or zsh. One way of running ...
1
vote
0answers
102 views

Zsh: quickly bookmark commands

I just had an idea, I'm sure it must exist though I could not find anything on the web. This topic gets close to my idea but not enough: How to quickly store and access often used commands? I'd like ...
5
votes
2answers
159 views

Passing glob expressions to functions/scripts

The following script is supposed to concatenate multiple csv files in a path specified in the first argument into a single csv file specified in the second argument #!/bin/zsh set -x set -v ...
1
vote
1answer
352 views

Getting “zsh: command not found: time” when running `time` in subshell

I installed ZSH (and Oh-My-ZSH) on a Ubuntu 12.10 64 bit machine a few days ago. I just tried to do: time (time ls) and got this error: zsh: command not found: time ( time ls; ) 0.00s user 0.00s ...