Posted: . At: 8:42 AM. This was 3 years ago. Post ID: 14796
Page permalink. WordPress uses cookies, or tiny pieces of information stored on your computer, to verify who you are. There are cookies for logged in users and for commenters.
These cookies expire two weeks after they are set.


Set up the ZSH shell on your system and personalize it easily.


The ZSH shell is a very customizable shell to use, and a good alternative to bash. There are a few associated files that can be used to personalize your ZSH shell.

The ~/.zlogin file is read when a user logs into a Linux account. This can be used to run commands when a terminal is opened to print various information.

~/.zlogin
1
2
3
4
5
6
7
8
9
#
# /etc/zlogin and .zlogin are sourced in login shells.  It should
# contain commands that should be executed only in
# login shells.  It should be used to set the terminal
# type and run a series of external commands (fortune,
# msgs, from, etc).
#
 
fortune ubuntu-server-tips

The ~/.zlogout file is read when a user logs out, this is useful to clear the screen when a user logs off a virtual terminal instance.

~/.zlogout
1
2
3
4
5
6
7
#
#
# /etc/zlogout and ~/.zlogout are run when an interactive session ends
#
#
 
clear

The ~/.zprofile is run for interactive shells. This is a nice place to put aliases and other important code.

#
# /etc/zprofile and ~/.zprofile are run for login shells
#

PATH="$PATH:$HOME/bin"
export PATH

_src_etc_profile()
{
    #  Make /etc/profile happier, and have possible ~/.zshenv options like
    # NOMATCH ignored.
    #
    emulate -L ksh

    # source profile
    if [ -f /etc/profile ]; then
	    source /etc/profile
    fi
}
_src_etc_profile

unset -f _src_etc_profile

Use the ~/.zshenv file to store all environment variables for your ZSH shell. Do not include scripts or commands to output text to STDOUT.

~/.zshenv
1
2
3
4
5
6
7
8
9
10
11
12
13
# /etc/zsh/zshenv: system-wide .zshenv file for zsh(1).
#
# This file is sourced on all invocations of the shell.
# If the -f flag is present or if the NO_RCS option is
# set within this file, all other initialization files
# are skipped.
#
# This file should contain commands to set the command
# search path, plus other important environment variables.
# This file should not contain commands that produce
# output or assume the shell is attached to a tty.
#
# Global Order: zshenv, zprofile, zshrc, zlogin

Here are some very useful ZSH aliases for you to use.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# listing stuff
#a2# Execute \kbd{ls -lSrah}
alias dir="command ls -lSrah"
#a2# Only show dot-directories
alias lad='command ls -d .*(/)'
#a2# Only show dot-files
alias lsa='command ls -a .*(.)'
#a2# Only files with setgid/setuid/sticky flag
alias lss='command ls -l *(s,S,t)'
#a2# Only show symlinks
alias lsl='command ls -l *(@)'
#a2# Display only executables
alias lsx='command ls -l *(*)'
#a2# Display world-{readable,writable,executable} files
alias lsw='command ls -ld *(R,W,X.^ND/)'
#a2# Display the ten biggest files
alias lsbig="command ls -flh *(.OL[1,10])"
#a2# Only show directories
alias lsd='command ls -d *(/)'
#a2# Only show empty directories
alias lse='command ls -d *(/^F)'
#a2# Display the ten newest files
alias lsnew="command ls -rtlh *(D.om[1,10])"
#a2# Display the ten oldest files
alias lsold="command ls -rtlh *(D.Om[1,10])"
#a2# Display the ten smallest files
alias lssmall="command ls -Srl *(.oL[1,10])"
#a2# Display the ten newest directories and ten newest .directories
alias lsnewdir="command ls -rthdl *(/om[1,10]) .*(D/om[1,10])"
#a2# Display the ten oldest directories and ten oldest .directories
alias lsolddir="command ls -rthdl *(/Om[1,10]) .*(D/Om[1,10])"
 
# some useful aliases
#a2# Remove current empty directory. Execute \kbd{cd ..; rmdir \$OLDCWD}
alias rmcdir='cd ..; rmdir $OLDPWD || cd $OLDPWD'

A very nice prompt setup for a ZSH shell.

# Where to look for autoloaded function definitions
fpath=($fpath ~/.zfunc)
READNULLCMD=${PAGER:-/usr/bin/pager}
echo -e "${CYAN}"
if [ -x /usr/games/fortune ] ; then
	echo
	fortune -l
	echo
	else
	echo -e "Fortune not found."
fi
echo -e "${NORMAL}"
echo -e "${YELLOW}"
echo -e "${INFO}"
echo -e "$NORMAL"
autoload -U compinit
compinit
autoload -U promptinit; promptinit
prompt clint white cyan red yellow

This collection of useful examples should really help you out and enable a user to have a very customizable ZSH shell.


Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.