Using the zsh shell and some useful tricks to make the most of this Linux shell.

Posted: November 18, 2012. At: 4:24 PM. This was 5 years ago. Post ID: 4868
Page permalink:

The zsh shell is a nice alternative to the bash shell when you are using Linux and want a nice command shell for your day-to-day use. Below is my ~/.zshrc files that I am using now. Type sudo apt-get install zsh to install this in Ubuntu. If you want to use my ~/.zshrc files; then you will need to install the fortune package to get a nice random fortune every time you open a terminal.

/etc/zsh-beta/zshrc: system-wide .zshrc file for zsh-beta(1).
export MAIL=/var/spool/mail/$USERNAME
export LESS=-cex3M
export EDITOR=vim
export HELPDIR=/usr/local/lib/zsh/help  # directory for run-help function to find docs
manpath=($X11HOME/man /usr/man /usr/lang/man /usr/local/man)
export WINDOWMANAGER=/usr/bin/startxfce4
export DOOMWADDIR=/usr/local/games
#export WINDOWMANAGER=/usr/bin/openbox
manpath=($X11HOME/man /usr/man /usr/lang/man /usr/local/man:/usr/share/man)
# Adding /usr/share/man to the search path for Mepis GNU/Linux.
export MANPATH
# Misc colors.
export NORMAL=" \e[0m"
export GREEN=" \e[1;32m"
export YELLOW=" \e[1;33m"
export WHITE=" \e[1;37m"
export CYAN=" \e[1;36m"
eval `dircolors -b`
# Use hard limits, except for a smaller stack and no core dumps
limit stack 8192
limit core 0
limit -s
umask 022
# Set up aliases
alias mv='nocorrect mv'       # no spelling correction on mv
alias cp='nocorrect cp'       # no spelling correction on cp
alias mkdir='nocorrect mkdir' # no spelling correction on mkdir
alias j=jobs
alias pu=pushd
alias po=popd
alias d='dirs -v'
alias h=history
alias grep=egrep
alias ll='ls -l'
alias la='ls -a'
alias cls='clear'
alias lu='ls -hula'
# More useful Aliases.
alias tarunpack='tar -zxvf'
alias bz2unpack='tar -jxvf'
# List only directories and symbolic
# links that point to directories
alias lsd='ls -ld *(-/DN)'
# List only file beginning with "."
alias lsa='ls -ld .*'
# This code courtesy of Emacs.
# Not everyone has finger(1).
if [ -x /usr/bin/finger ] ; then
	INFO=$(finger -lmps $LOGNAME | fgrep On )
	alias userlist='finger -lmps'
	INFO=$(uname -msov)
	alias userlist='users'
# Shell functions
	typeset -x "${1}${1:+=}${(@)argv[2,$#]}"
}  # csh compatibility
	while (( $# )); do; unfunction $1; autoload -U $1; shift; done
# These following functions from
function my_ip() # get IP adresses. Bracket on next line C style...
    MY_IP=$(/sbin/ifconfig ppp0 | awk '/inet/ { print $2 } ' | sed -e s/addr://)
    MY_ISP=$(/sbin/ifconfig ppp0 | awk '/P-t-P/ { print $3 } ' | sed -e s/P-t-P://)
function lowercase()  # move filenames to lowercase.
    for file ; do
        case "$filename" in
        */*) dirname==${file%/*} ;;
        *) dirname=.;;
        nf=$(echo $filename | tr A-Z a-z)
        if [ "$nf" != "$filename" ]; then
            mv "$file" "$newname"
            printf "lowercase: $file --> $newname\n"
            printf "lowercase: $file not changed.\n"
# Where to look for autoloaded function definitions
fpath=($fpath ~/.zfunc)
printf "${CYAN}"
if [ -x /usr/bin/fortune ] ; then
	fortune -l
	    printf "Fortune not found."
printf "${NORMAL}"
printf "${YELLOW}"
echo -e "${INFO}"
printf "$NORMAL"
autoload -U compinit
autoload -U promptinit; promptinit
prompt clint white cyan red yellow

This ~/.zshrc file gives a nice looking shell prompt and will make your terminals look very nice indeed. This is what the prompt looks like.

[Sun 12/11/18 15:52 EST][pts/1][x86_64/linux-gnu/3.5.0-17-generic][5.0.0]
zsh/4 2 %

If you type prompt at the zsh shell prompt and then hit the TAB key you will get a list of prompt themes that are available to use.

Sun 12/11/18 16:09 EST][pts/1][x86_64/linux-gnu/3.5.0-17-generic][5.0.0]
zsh/4 14 % prompt
adam1    adam2    bart     bigfade  clint    elite    elite2   fade     fire     off      oliver   pws      redhat   suse     walters  zefram

And help is available for each theme using the -h parameter to the prompt command.

[Sun 12/11/18 16:09 EST][pts/1][x86_64/linux-gnu/3.5.0-17-generic][5.0.0]
zsh/4 13 % prompt -h elite2                  
Help for elite2 theme:
This prompt is color-scheme-able.  You can invoke it thus:
  prompt elite2 [<text-color> [<parentheses-color>]]
The default colors are both cyan.  This theme works best with a dark
Recommended fonts for this theme: either UTF-8, or nexus or vga or similar.
If you don't have any of these, the 8-bit characters will probably look
Type `prompt -p elite2' to preview the theme, `prompt elite2'
to try it out, and `prompt -s elite2' to use it in future sessions.

Some useful zsh tricks:

And a comprehensive list of zsh commands and tricks here:

No comments have been made. Use this form to start the conversation :)

Leave a Reply