Zsh

From WTFwiki
Jump to navigation Jump to search
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

Zsh is a very configurable UNIX shell. Here's some tricks to make it do some handy stuff:

Display your TODO file on login

How about showing your TODO file (so you can remember to get shit done) every time you open a new shell?

 # print contents of TODO file :) - stolen from jon
 if [ -f ~/TODO ]; then
         echo ""
         echo " ---- TODO ----"
         cat TODO
 fi

Prompt

How about doing some fancy things with the prompt?

 #set a fancier prompt if we're root (the 'root' part becomes red)
 #The prompt begins with ^ if the last command was a success, _ if it failed
 if [ `whoami` = root ]
 then
         PROMPT=$'%(?,^,_)%{\e[0;31m%}%n%{\e[0;36m%}@%m%{\e[0;37m%}:: '
 else
         PROMPT=$'%(?,^,_)%{\e[0;36m%}%n@%m%{\e[0;37m%}:: '
 fi
 #set the right edge prompt with the pwd
 RPROMPT=$'%{\e[0;37m%}[$green%.%{\e[0;37m%}]'

The prompt's format is [^_]username@host:: with some color tags..., the RPROMPT is shown at the right side of the line(it vanishes if the input line gets too long).

For a related prompt hack, see OpenBSD CARP router/firewall zsh shell prompt

Home/End keys

If your home/end keys don't do what you want, try this:

 #make home/end work in as many places as possible
 case $TERM in
     *xterm*|*rxvt|(dt|k|E|a)term)
         bindkey "\e[7~" beginning-of-line
         bindkey "\e[8~" end-of-line
     ;;
     screen*)
         bindkey "\e[1~" beginning-of-line
         bindkey "\e[4~" end-of-line
     ;;
     cons25)
         bindkey "\e[H" beginning-of-line
         bindkey "\e[F" end-of-line
     ;;
 esac

Colors

 #Colors
 export red=$'%{\e[0;31m%}'
 export RED=$'%{\e[1;31m%}'
 export green=$'%{\e[0;32m%}'
 export GREEN=$'%{\e[1;32m%}'
 export blue=$'%{\e[0;34m%}'
 export BLUE=$'%{\e[1;34m%}'
 export purple=$'%{\e[0;35m%}'
 export PURPLE=$'%{\e[1;35m}'
 export cyan=$'%{\e[0;36m%}'
 export CYAN=$'%{\e[1;36m}'
 export WHITE=$'%{\e[1;37m}'
 export white=$'%{\e[0;37m}'
 export NC=$'%{\e[0m%}'

--Andrew 22:55, 28 September 2006 (EDT)