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

learn more… | top users | synonyms (1)

34
votes
3answers
9k views

ESC key causes a small delay in terminal due to its Alt+ behavior

My terminal setup is gnome-terminal + tmux + zsh with vi bindings. In applications like vim or even in the zsh's command line vi editing mode, I need to frequently hit the ESC key but there is a ...
7
votes
2answers
2k views

Difference between alias in zsh and alias in bash

I have searched around but could not find anything conclusive. Is there a difference between the alias command in zsh and the alias command in bash? If not, does it mean I can share a set of aliases ...
1
vote
1answer
275 views

Delete zsh auto completion suggestion

When I use tab-completion in zsh, the shell suggests me files and I discover that I'm in the wrong directory. How can I just delete the suggestion instead of backspace'ing it?
9
votes
2answers
4k views

Multidigit ranges of files in lexicographical order in zsh

I would like to specify a range of files (in lexicographical order) with two integers (e.g. 2 to 57) in zsh by globbing. For example: "pick the files 2 to 57 in lexicographical order under the path ...
2
votes
1answer
324 views

Globbing with brackets and variables in zsh

I wrote the following snippet to delete several subdirectories selectively from a common ancestor. It doesn't work, but I can't tell why. for x in *; do rm -r "$x/foo/bar/{a*,b,c,d,g*}"; done I ...
2
votes
2answers
489 views

How to cd into the named directory if command not found?

When I type something which is neither a zsh builtin and no such executable is found from $PATH, zsh just reports an error. Instead, I would like zsh to check if a named directory exists with that ...
32
votes
1answer
1k views

Avoiding “BASH-isms” in shell scripts

Does there exist a tool similar to Perl::Critic that will inspect your shell scripts and point out flaws, portability issues, uses of non-standard programs without fallbacks, depreciated program uses, ...
0
votes
2answers
3k views

SSH “command not found” for Zsh

Im using Zsh on the client and server. When I use ssh to run a command on the remote server it can not find the binary: ssh gt "cd /home/****/app/staging && bundle exec rake db:migrate ...
9
votes
2answers
3k views

Testing LS_COLORS in zsh

A few years ago I found an interesting code snippet that prints each type of file in its corresponding color according to the colors set up in LS_COLORS. Unfortunately, I can't remember the link ...
1
vote
2answers
9k views

Why doesn't the following work?: while true; do “$my_command”; sleep 1; done

Following up on the top answer to this question, I thought I could: 1) Define a command: cmd='for x in $(my_command | grep keyword | cut -d" " -f1); do command2 "arguments" $x; done' 2) Run it ...
2
votes
1answer
137 views

History-search in zsh working only for commands?

Say I have the following entries in my command history: less documents/doc1.txt less documents/doc2.txt less files/file1.txt less files/file2.txt ls pwd and that I have the following keyboard ...
3
votes
2answers
1k views

Concatenating columns horizontally. Printing only rows that intersect on 1st column

Say I have two different commands that output contents by columns, e.g.: $ command_1 7049857 abc fdg hsi 5409858 xxx fyy hsi 540958 abc zzz hsi 54230956 rbc sss hsi $ command_2 7049857 0 fdg ...
1
vote
2answers
176 views

How to change the interpret of a variable in `zsh`?

I set a variable TEMPP='-I ../dir1 -I ../dir2' then I run gcc -M $TEMPP somefile.c It seems not to include ../dir1 and ../dir2 in the search list of the include file, and if there is a space at the ...
34
votes
1answer
38k views

For loops in zsh and bash

I have noticed there are two alternative ways of building loops in zsh: for x (1 2 3); do echo $x; done for x in 1 2 3; do echo $x; done They both print: 1 2 3 My question is, why the two ...
4
votes
2answers
1k views

Counting files in leaves of directory tree

I came up with the following snippet for counting files in each subdirectory: for x (**/*(/)); do print $x; find $x -maxdepth 1 -type f | wc -l; done The command outputs consecutive pairs (one ...
7
votes
1answer
5k views

Arrays and loops in zsh

I am trying to learn loops and array manipulation in zsh. Say I have two arrays in zsh with the same unknown # of elements and each of them containing a list of paths, e.g. LOCAL_ARRAY=($...
1
vote
2answers
956 views

find -exec on zsh: echo works as expected, print doesn't

I thought the following two commands would output the same thing, but they don't: Command 1: find . -name filename -exec print '{}' \; Command 2: find . -name filename -exec echo '{}' \; ...
5
votes
5answers
479 views

Conflict between my prompt definition and cat in zsh

I have a file on a remote filesystem that I know has a short text string in it (a sequence of numbers in a single line). If I open the file on a text editor like nano or Emacs I can see the string. ...
2
votes
1answer
2k views

What does “trace trap” mean when reported by zsh?

I am trying to run a set UID root program in UNIX using the zsh shell. But I keep getting this message $ ./progExe zsh: trace trap ./progExe Can anyone please tell what does “zsh: trace trap” mean?
3
votes
1answer
209 views

Definition of word in ZLE (zsh)

I came across the following two snippets in zsh: Snippet 1: autoload select-word-style select-word-style shell Snippet 2: setopt shwordsplit My question is, what is the difference between ...
7
votes
1answer
12k views

Running a bash script from a zsh shell

I'm having problems running a bash script on zsh. The script is similar to the one below and is supposed to run under bash: #!/bin/bash echo "<235234>" | egrep -oe [0-9]+ However, my shell ...
1
vote
1answer
657 views

How to manipulate awk variable NF in zsh?

I have a simple command line: uptime | awk '{print $(NF - 2)}' In a bash shell, this works without a hitch, but when I run it in zsh, I get the following error: title:5: command not found: NF As ...
3
votes
2answers
552 views

Issues with Vim while using ZSH

I just changed my shell to ZSH. However, when I tried to edit a .py file in vim I got a strange error: "test.py" [New File] Error detected while processing /usr/local/share/vim/vim73/ftplugin/...
5
votes
1answer
386 views

Adding more Emacs-like bindings to ZSH's line editor (ZLE)

I have a couple of questions regarding the emacs-like keyboard bindings in Zsh. As background to all the questions: I have Emacs-like keybinding activated with bindkey -e (activated by default) ...
6
votes
1answer
709 views

ZSH: Globbing the first N files under a path in lexicographic order

I was wondering if there is a way to specify the first N files under a given a directory in zsh. I am interested in solutions for recursive enumeration (i.e. any file recursively below a path is ...
2
votes
1answer
3k views

Understanding colors in zsh

In this thread, yoda suggests the following solution for using colors in zsh #load colors autoload colors && colors for COLOR in RED GREEN YELLOW BLUE MAGENTA CYAN BLACK WHITE; do eval $...
3
votes
1answer
404 views

.zshrc and the configuration function

I called zsh from Bash for the first time in my machine after installing it. Then I followed the instructions in the menu from the configuration function and saved the changes. So far so good, I can ...
6
votes
1answer
251 views

How can I output “temporarily” to the shell, like zsh tab completion does?

In zsh shell, when you hit Tab twice to get tab completion, your options are displayed below your prompt. But when you make a selection, the options disappear. I have a little script that outputs ...
1
vote
1answer
232 views

Printing evaluated prompt placeholders to screen

Is there a way to print interpreted PS1 variable placeholders to console? Something like $ echo `%u` for printing a username or $ echo `%h` for printing a host. I do know about environment ...
9
votes
1answer
983 views

What is the best way to detect (from a script) whether software is installed?

I've been frustrated before with differences in output from the which command across different platforms (Linux vs. Solaris vx. OS X), with different shells possibly playing into the matter as well. ...
7
votes
1answer
348 views

in zsh, how do I hide the backslashes in the completion menu

On Mac OS X 10.6, zsh. I have set in .zshrc: setopt automenu …to get a completion menu below the prompt. When I type: cd <TAB> I see a completion menu with all directories that have spaces ...
4
votes
2answers
1k views

ZSH tab completion: only complete files and not binaries

Is it possible to make a custom zsh completion file,so when hitting tab for filenames it avoids completing the binaries? For example,I have 2 files , myprogram.c and myprogram,the binary,is it ...
4
votes
1answer
324 views

_path_files and compadd ignore-files parameter

What is the format for the -F option of _path_files and compadd? I'm passing several directories to _path_files: _path_files -W "($base_directories)" -/ But some of those directory trees I don't ...
9
votes
2answers
2k views

How do you make RPROMPT in zsh update itself on every enter?

My RPROMPT is set to display svn info using vcs_info. It reads RPROMPT=${vcs_info_msg_0_}. vcs_info is called using precmd(). However, RPROMPT doesn't update when I change directories. It works only ...
3
votes
1answer
983 views

ignore hosts file in ZSH ssh/scp tab-complete

I use a hosts file to block ads/malware domains. When I use ssh or scp in zsh and try to tab-complete, it takes a good 5-10 seconds before anything appears and what does appear is usually a list of 20+...
2
votes
1answer
3k views

zsh and xfce4-terminal

I've changed my login shell to zsh from bash on an installation of Debian Squeeze with XFCE. When I launch xfce4-terminal, zsh starts but does not load my configuration. I have searched high and low,...
6
votes
1answer
2k views

ZSH: insert completion on first tab even if ambiguous?

Currently ZSH displays a menu when I first hit tab and the completion is ambiguous. So, if I have 'cd ' in the command prompt and I hit tab, it will show the different available completions. If I hit ...
3
votes
3answers
1k views

Is there a way to make the prompt definition multiline?

This is my current prompt definition: PS1=$'%F{063}%1~%f %(1v.%F{099}%1v %f.)%F{063}%%%f ' RPROMPT='$VIMODE %m' and I'm working on integrating this. Basically I'm starting to find it very ...
3
votes
1answer
371 views

zsh history - full path

Suppose I do the following in zsh cd ~ cd dir1 cd dir2 cd dir3 evince foo.pdf zsh writes exactly the same in its history file. Now my question is whether it is possible to have cd ~ cd ~/dir1 cd ...
3
votes
1answer
596 views

zle - I cannot find why Ctrl+R does not work for non-root

The Ctrl+R works for root (well toor) however I cannot find why it does not work for user. User .zshrc: setopt AUTO_CD setopt CORRECT_ALL setopt EXTENDED_GLOB # History SAVEHIST=10000 HISTSIZE=10000 ...
3
votes
2answers
132 views

Hiding a zsh completion

I just switched to zsh (from tcsh) and have only run into one serious frustration: There are multiple completions for push — pushd and pushln. I’d really like to only have pushd available, since ...
6
votes
1answer
394 views

Can I have my shell history record how wildcards expanded?

If I run: $ ls * foo bar buzz $ history | tail -1 ls * You can see that in my shell history it remembers that I ran ls * rather than ls foo bar buzz. Ideally, I'd like to record both in separate ...
2
votes
1answer
259 views

Switch back to path when resume job from background

Say I open ~/vim.txt, push that to background, then cd to another path. When I bring that job to foreground, is there an option to switch back to old path? I noticed it says pwd, so I assume it is ...
5
votes
1answer
1k views

zsh equivalent of bash show-all-if-ambiguous?

In bash, if you hit tab when there are multiple possible completions you get a list of matches that keeps reprinting if you repeatedly press tab. In tcsh, setting autocomplete to enhanced also ...
3
votes
2answers
847 views

ANDed conditional using regexp and variables

I want to test whether a line, read in from a file, has a specific beginning AND an ending containing a word held in a variable. Here's some code: The input file is: line one #; line two #; line ...
3
votes
1answer
487 views

What does %F mean and how can I stop it meaning it?

On an rxvt-clone (I'm using rxvt-unicode but it seems to happen on plain, old rxvt as well), the sequence of characters %F seems to have some sort of special meaning (as do a few others, such as %S). ...
3
votes
2answers
1k views

The Right Distro for text-based needs

I'm searching for the right Linux Distro. My four current ideas are: Gentoo Grml Arch Debian But I'm absoluty open to more alternatives. Now a little bit more about my needs: I want it to be ...
4
votes
2answers
1k views

zsh alias expansion

Is it possible to configure zsh to expand global aliases during tab completion? For example, I have the common aliases: alias -g '...'='../..' alias -g '....'='../../..' but when I type for ...
24
votes
1answer
5k views

Is it possible to have vim key bindings in terminal?

I'm getting used to vim bindings (like pressing w to go to word, dw to delete a word, and such) and it's modes (insert, normal, visual), and, out of curiosity would like to know: is there some kind of ...
10
votes
1answer
1k views

How do I get my shell functions to make use of existing autocompletion in zsh?

I have a couple of shell functions defined in my .zshrc which save on typing and allow integration with screen. For example: function s() { screen -t "$1" ssh "$@" } However, when I use these ...