Zsh Alias Cheat Sheet
Categorizing the different ways aliases can be used.
(Work in Progress)
v0.1 23 Jan 2022 Probably contains errors please email any comments to zzapper@gmail.com
zzapper's ZSH home
The most common type
alias gp='egrep -i'
alias ll='ls -lt'
alias gits='git status'
alias lmpg='ls *.(wmv|mpg|mov|avi)' # list any videos
alias phpn='php -l *.php(.om[1])' # syntax check newest
alias vini='vi /etc/php/7.4/apache2/php.ini'
alias vip='vi index.php'
alias dtrash='cd ~/.local/share/Trash/files'
alias dbin='cd /usr/local/bin/'
technique by placing the 'parameter' at the end
alias gia='< ~/.zshrc | grep -ia'
gia photo
alias gia='f(){grep -i "$1" ~/.zshrc};f'
gia photo
crucial difference between single (dynamic) & double quotes (static) for aliases
alias dxd="echo $(date)" # Double quotes
dxd # always the date when alias created
alias dxs='echo $(date)' # Single Quotes
dxs # dynamically re-evaluated
When complex quoting required
When complex quoting required
alias lsimg=$'for f (*.(jpeg|jpg|gif|png)) {printf $f;php -r "print_r(getimagesize(\'$f\'));" |grep -w width |sed \'s/ .3] =>//\'}'
alias -s {odt,doc,docx}='soffice --writer'
alias -s {gif,png,jpg}='xnview'
alias -s pdf='xreader'
Example
then just type file name to open in specified app
cat.jpg # opens in XnViewMP
Just displays the alias definiton
alias -L 'G' 'GV' # note the quotes
alias -g G=' | grep -iaE' # grep pipe
alias -g GV=' | grep -ivaE' # negative grep pipe
Can Appear anywhere on the Command Line
alias -g G=' | grep -i'
alias -g GV=' | grep -ivaE' # negative grep pipe
alias -g H=' | head '
alias -g M=' | less '
alias -g CO=' | xclip -sel clip'
Example
grep projectxy *.log M
e.g. search for an image
locate bridge G railway GV backup CO
xxxdetailxxx
alias -g TOH=' *(.mh0)' # last hours files
alias -g TOD=' *(.m0)' # today's files
alias -g TOW=' *(.mw0)' # last week files
xxxdetailxxx
alias -g NFI='**.(jpg|gif|png|jpeg)(.om[1])' # newest image in hierarchy
alias -g TW='*.(php|css|js)(.m0)' # Todays web files
vi TW # re-edit todays web files
/ = dir . = file
alias -g ND1='*(/om[1])' # newest dir
alias -g ND2='*(/om[2])' # 2nd newest dir
alias -g NF1='*(.om[1])' # newest file
cp NF ND
xxxdetailxxx
instead of having many different aliases use generic
aliases which you expand and modify as required
~ means directories/files to exclude
alias -g GLOB=' **.(php|inc|js)~(libs|test)/*'
ll GLOB to Expand
Then tweal the glob as required
Basic Templates for complex syntax for commands such as awk & sed
alias -g AWK=$' | awk \'{print cnt++,$3,$4}\'' # Ansi C quoting
alias -g SED=$' | sed \'/color/ s/red/green/g\''
TAB Expand and then tweak as required
only work after being TAB expanded
Use an Alias to Access a locate result
alias LF1='eval ${$(!!)[1]} E'
alias LF2='eval ${$(!!)[2]} E'
alias LD1='cd ${$(!!)[1]:h} ' # cd to 1st
alias LD2='cd ${$(!!)[2]:h} '
xxxdetailxxx
for n ({1..5}) alias -g NF$n="*(.om[$n])"
e.g. this gives you
vi NF4 # edit 4th newest file
An alias to remind of of a greoup of aliaises e.g. for tmux
alias tmxh="alias -L 'tmx' 'tmxk' 'tmxn' 'tmxc'"
tmxh
alias tmx='tmux new-session \; split-window -v \; split-window -h \;'
alias tmxk='tmux kill-server'
alias tmxn='gvim tmux_notes.txt'
alias tmxc='gvim ~/.tmux.conf '
display complex options
configured to auto-expand
alias -g OLDH='*(.mw+3) # m=minutes,d=days(default), w=week,M=Month +n older than n,-n younger'
aliases may include aliaises
alias a1='echo sue'
alias b1='echo tom'
alias c1='a1;b1'
c1
sue
tom
xxxdetailxxx
alias sysload='printf "System load (1m/5m/15m): "; for l in 1 2 3 ; do printf "%.1f%s" "$(( $(cat /proc/loadavg | cut -f $l -d " ") * 100 / $(nproc) ))" "% "; done; printf "\n"'
sysload
System load (1m/5m/15m): 16.2% 25.0% 25.2%
\ \_____
###[==_____>
/_/