We\'ve detected that you\'re using AdBlock Plus or some other adblocking software. Please be aware that this is only contributing to the demise of the site. We need money to operate the site, and almost all of that comes from our online advertising.

Linux tips and tricks for all users.

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

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"

MAILCHECK=300
HISTSIZE=200
DIRSTACKSIZE=20

eval `dircolors -b`

# Use hard limits, except for a smaller stack and no core dumps
unlimit
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'
else
	INFO=$(uname -msov)
	alias userlist='users'
fi

# Shell functions
setenv()
{
	typeset -x "${1}${1:+=}${(@)argv[2,$#]}"
}  # csh compatibility
freload()
{
	while (( $# )); do; unfunction $1; autoload -U $1; shift; done
}

# These following functions from http://www.die.net/doc/linux/abs-guide/sample-bashrc.html
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
        filename=${file##*/}
        case "$filename" in
        */*) dirname==${file%/*} ;;
        *) dirname=.;;
        esac
        nf=$(echo $filename | tr A-Z a-z)
        newname="${dirname}/${nf}"
        if [ "$nf" != "$filename" ]; then
            mv "$file" "$newname"
            printf "lowercase: $file --> $newname\n"
        else
            printf "lowercase: $file not changed.\n"
        fi
    done
}

# Where to look for autoloaded function definitions
fpath=($fpath ~/.zfunc)

READNULLCMD=${PAGER:-/usr/bin/pager}

printf "${CYAN}"

if [ -x /usr/bin/fortune ] ; then
	fortune -l
	else
	    printf "Fortune not found."
fi

printf "${NORMAL}"

printf "${YELLOW}"
echo -e "${INFO}"
printf "$NORMAL"

autoload -U compinit
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]
<john@deusexmachina:~/Documents>
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]
<john@deusexmachina:~/Documents>
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]
<john@deusexmachina:~/Documents>
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
background.

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
stupid.

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: http://chneukirchen.org/blog/archive/2008/02/10-zsh-tricks-you-may-not-know.html.

And a comprehensive list of zsh commands and tricks here: http://www.rayninfo.co.uk/tips/zshtips.html.

Post a Comment

Your email is kept private. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Current day month ye@r *