User Tools

Site Tools


zsh

Config

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 () {
  local WORDCHARS=${WORDCHARS//\//}
  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
setopt RM_STAR_WAIT

# Don’t nice background processes
setopt NO_BG_NICE

# Watch other user login/out
watch=notme
export LOGCHECK=60

# make every cd command also a pushd
setopt autopushd

Tips&Tricks

Globbing

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: https://www.evernote.com/shard/s9/note/d6443525-ad9a-4468-8696-29dd68f9010d/wishi/crazylazy#b=5370c944-5bb8-45c1-b73a-cfe46216db32&n=d6443525-ad9a-4468-8696-29dd68f9010d

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