As you say, zsh
is similar in many respects to bash
. It has some features you won't find in bash
, and it can be extended in powerful ways. Don't think of moving as a kind of revolution, but rather as a series of evolutionary steps that help you in your daily work. Here are some hints from my .zshrc
. Although you say you prefer single pieces of advice, this post is a longish list. Still it is a good idea to go through the points one by one. Just add the interesting bits to your ~/.zshrc
and reload with source ~/.zshrc
. A final tip: learn the keystrokes of zsh
's default ("Emacs") keyboard shortcuts: ^A ^E ^W Alt-F Alt-B Alt-P ^L ^R
. You can replace Alt
by two separate keystrokes: Alt-P
is equivalent to ESC
P
.
This gives you more extensive tab completion.
autoload -U compinit
compinit
Tab completion from both ends.
setopt completeinword
Tab completion should be case-insensitive.
zstyle ':completion:*' matcher-list 'm:{a-zA-Z}={A-Za-z}'
Better completion for killall.
zstyle ':completion:*:killall:*' command 'ps -u $USER -o cmd'
Changes the definition of "word", e.g. with ^W.
autoload select-word-style
select-word-style shell
Colors for ls.
if [[ -x "`whence -p dircolors`" ]]; then
eval `dircolors`
alias ls='ls -F --color=auto'
else
alias ls='ls -F'
fi
Shortcuts for ls.
alias ll='ls -l'
alias la='ls -a'
One history for all open shells; store 10,000 entries. This makes this into a useful memory aid to find the commands you used last time for ./configure
etc. Use Alt-P (find command that starts like this) and ^R (search in history) liberally.
HISTFILE=~/.zhistory
HISTSIZE=SAVEHIST=10000
setopt sharehistory
setopt extendedhistory
Enables all sorts of extended globbing, such as ls **/*.txt (find all text files), ls -d *(D)
(show all files including those starting with "."). To find out more, go to man zshexpn
, section "FILENAME GENERATION".
# superglobs
setopt extendedglob
unsetopt caseglob
This is useful to remember commands in your history without executing them.
setopt interactivecomments # pound sign in interactive prompt
Type ".." instead of "cd ..", "/usr/include" instead of "cd /usr/include".
setopt auto_cd
Nice prompt.
PS1='[%T] %n@%m:%~# '
Display CPU usage stats for commands taking more than 10 seconds
REPORTTIME=10
Some commands you use extensively in Ubuntu.
alias 'a=sudo aptitude'
alias 'ai=sudo aptitude install'
alias 'ar=sudo aptitude remove'
alias 'au=sudo aptitude update'
alias 'ag=sudo aptitude safe-upgrade'
alias 'as=apt-cache search'
alias 'aw=apt-cache show'
Lists packages sorted by their size - useful when deciding which packages are taking up you disk space.
function apt-list-packages {
dpkg-query -W --showformat='${Installed-Size} ${Package} ${Status}\n' | grep -v deinstall | sort -n | awk '{print $1" "$2}'
}
source /etc/zsh_command_not_found
to your.zshrc
.