User Tools

Site Tools



zsh is very nice and powerful. Here are some things to put into your .zshrc

Make the completion show all files in a directory

#turns the key \C-x F into a command complete-file 
#(which goes straight to the completion system's file completion command, ignoring the normal context)
zle -C complete-file complete-word _generic
zstyle ':completion:complete-file::::' completer _files
bindkey '^F' complete-file

Now pressing CTRL-f at any time makes the completion show (and suggest) all the files in the directory

Delete Path Elements

# make ALT+<Backspace> delete backwards until last slash (very useful when editing paths)
backward-delete-to-slash () {
  zle .backward-delete-word
zle -N backward-delete-to-slash
bindkey "^[^?" backward-delete-to-slash

Misc useful options

# Allow comments in interactive shell
setopt interactivecomments

# Say how long a command took, if it took more than 30 seconds
export REPORTTIME=30

# Prompts for confirmation after 'rm *' etc ...Helps avoid mistakes like 'rm * o' when 'rm *.o' was intended

# Don’t nice background processes
setopt NO_BG_NICE

# Watch other user login/out
export LOGCHECK=60

# make every cd command also a pushd
setopt autopushd



See “man 1 zshexpn” for documentation. Some examples:

vi **/muh.txt                       # edit muh.txt no matter in which subdirectory it hides
echo *(oL)                          # sort directory contents by size
echo *(om)                          # sort directory contents by modification time
echo **/*(F)                        # list full directories
echo **/*(/^F)                      # list empty directories (NOT full)
echo *(m4)                          # list files modified exactly 4 days ago

more examples:

zsh.txt · Last modified: 2012/07/05 18:29 by hkoller