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

learn more… | top users | synonyms (1)

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
198 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
832 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
579 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
64 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
100 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
165 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
175 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
110 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
695 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
143 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
181 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
136 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
505 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
288 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
290 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 ...
10
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
499 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
203 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
120 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
167 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
154 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
119 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
299 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
124 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
117 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
242 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
571 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
146 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
263 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
109 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
188 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
397 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 ...
12
votes
6answers
1k views

Portable way to get script's absolute path?

What is a portable way for a (zsh) script to determine its absolute path? On Linux I use something like mypath=$(readlink -f $0) ...but this is not portable. (E.g., readlink on darwin does not ...
0
votes
1answer
53 views

Weird behavior when sourcing .zshrc

I'm using zsh 5.0.2 (x86_64-apple-darwin12.3.0) on the latest MacOSX. If it makes any difference, I have also enabled oh-my-zsh. The shell seems to be missing the .zshrc file when I want to source ...
3
votes
1answer
95 views

Ignore files for zsh's completion for SVN

I managed to configure zsh such that it does not suggest LaTeX temporary files when I use autocompletion for emacs by adding this line to my ~/.zshrc: zstyle ':completion:*:*:emacs:*:*files' ...
0
votes
1answer
238 views

Issues using sublime text to edit command line in VI mode

I am using the following to edit the current command line in Sublime Text 2 (using a working subl alias) .zshrc set -o vi EDITOR='subl'; export EDITOR bindkey -M vicmd v edit-command-line ...
2
votes
0answers
108 views

zsh: Echoing every statement?

I have an odd problem with zsh when I switch between shells in a particular way: Option 1 (works well): I start a zsh shell. I switch to tcsh with /bin/tcsh, and I switch back to zsh with /bin/zsh ...
2
votes
0answers
133 views

Is there a postexec/predisplay hook for ZSH?

I know zsh has a preexec hook that fires before the command is executed, but is there one that fires after the command has been initiated but before the output is displayed to the screen? I ask ...
2
votes
2answers
2k views

/usr/bin/env: zsh -: No such file or directory

I get the error /usr/bin/env: zsh -: No such file or directory ...when I run an executable zsh script that starts with the following shebang line: #!/usr/bin/env zsh - Also, FWIW, replacing - ...
6
votes
4answers
2k views

Hybrid code in shell scripts. Sharing variables

This answer discusses how to run a multi-line Python snippet from the command line in a terminal. I noticed that the answer works great within shell scripts, even with nested indentation, which is ...
5
votes
2answers
521 views

Wrap command in the prompt

Is it possible to insert a separator after the command in a prompt? This is an example: ~/Desktop: ls -al ------------------------------------- total 80 drwx------+ 6 eddie staff 204B Apr 29 ...
5
votes
3answers
427 views

How to save current command on zsh? [duplicate]

I am typing a command, I remember I have to check something, if I press Ctrl+U the command disappears and I can type something else, but then the command I was typing is not in the history. Is there ...
2
votes
1answer
117 views

What does %\/ do (zsh prompt expansion)?

What does the sequence %\/ do in zsh prompt expansion? man zshmisc doesn't contain the string %\, which is where the rest of the prompt-specific expansions are. The sequence can be seen in Holmans ...
3
votes
4answers
181 views

Expansion with numbers in human readable format

So, I want to play some MP3s in a console player that takes file names as inputs. I have the following files, as given by ls -1 * where * get expanded by my shell (zsh): 1 - Main title.mp3 10 - End ...
5
votes
2answers
182 views

Modifying zsh globbing patterns to use with cp

I'm trying to write a script to copy files recursively from a particular folder except files A.extn, B/*.extn and C/* where B and C are directories and extn is just some generic extension. This is ...
2
votes
3answers
200 views

How can a zsh script test whether it is being sourced?

The accepted answer for a similar question for bash does not seem to work for zsh. In fact, if I copy basically the same code given in that answer, to produce the script #!/usr/bin/zsh - # test.sh ...
2
votes
1answer
106 views

zsh - check arguments of a command before executing it

Question: Is there an easy way how I can teach zsh to check the command line before executing it? I know that I can completely wrap a specific program with an extra script, but this is not what I want ...