my zshrc
Date: August 2, 2012
so after many years of using sh & bash i have decided to give zsh a try and after using it for a couple of weeks i cant go back.
so here is my zshrc @ github for people to use.
in detail (at time of writing this was my current zshrc):
#### interactive shell check #### {
if [[ $- != *i* ]] ; then
return
fi
#### end interactive check #### }
#### exports #### {
export LANG=en_US.UTF-8
export LC_ALL=en_US.UTF-8
export TERM=screen-256color
#### end exports #### }
#### zsh key bindings #### {
bindkey '^A' beginning-of-line # ctrl-a beginning of line binding
bindkey '^E' end-of-line # ctrl-e end of line binding
bindkey '^R' history-incremental-search-backward # ctrl-r history incremental search backwards
bindkey '^[[2~' overwrite-mode # insert key overwrite mode
bindkey '^[[3~' delete-char # delete key fix
bindkey '^[[7~' beginning-of-line # home key
bindkey '^[[8~' end-of-line # end key
bindkey -v
#### end zsh key bindings #### }
#### zsh history #### {
HISTFILE=$HOME/.zsh_history
HISTSIZE=10000
SAVEHIST=10000
setopt APPEND_HISTORY # append rather than overwrite history file.
setopt EXTENDED_HISTORY # save timestamp and runtime information
setopt HIST_EXPIRE_DUPS_FIRST # allow dups, but expire old ones when I hit HISTSIZE
setopt HIST_FIND_NO_DUPS # don't find duplicates in history
setopt HIST_IGNORE_ALL_DUPS # ignore duplicate commands regardless of commands in between
setopt HIST_IGNORE_DUPS # ignore duplicate commands
setopt HIST_REDUCE_BLANKS # leave blanks out
setopt HIST_SAVE_NO_DUPS # don't save duplicates
setopt INC_APPEND_HISTORY # write after each command
setopt SHARE_HISTORY # share history between sessions
#### end zsh history #### }
#### ls colors zsh #### {
if [[ -x "`whence -p dircolors`" ]]; then
eval `dircolors`
alias ls='ls -F --color=auto'
else
alias ls='ls -F'
fi
#### end ls colors #### }
#### zsh super globs #### {
setopt NO_CASE_GLOB # case insensitive globbing
setopt NUMERIC_GLOB_SORT # numeric glob sort
setopt extendedglob
unsetopt caseglob
#### end super globs #### }
#### misc zsh options #### {
setopt NO_BEEP # no more beeps
#### end misc zsh options #### }
#### aliases and functions #### {
# alias speak_date='espeak “Today is `/bin/date \â€+%A, %d %B 20%y\â€`â€â€˜
# alias speak_time='espeak "Time is `/bin/date` \"+%H hours %M minutes %S seconds\""'
alias add='git add .'
alias commit='git commit .'
alias cpv="rsync -poghb --backup-dir=/tmp/rsync -e /dev/null --progress --"
alias dud100='du -a --max-depth=1 | sort -n | awk '\''{if($1 > 102400) print $1/1024 "MB" " " $2 }'\'''
alias dud='du --max-depth=1 -h'
alias duf='du -sk * | sort -n | while read size fname; do for unit in k M G T P E Z Y; do if [ $size -lt 1024 ]; then echo -e "${size}${unit}\t${fname}"; break; fi; size=$((size/1024)); done; done'
alias irc='if [[ $USER == root || `ps -ef | egrep tmux | egrep -v egrep | wc -l` -eq 0 ]] ; then irssi ; else tmux rename-window "irc" && irssi ; fi'
alias mail='if [[ $USER == root || `ps -ef | egrep tmux | egrep -v egrep | wc -l` -eq 0 ]] ; then mutt ; else tmux rename-window "emails" && mutt ; fi'
alias o='popd'
alias p='pushd'
alias push='git push origin master'
alias same="find . -type f -print0 | xargs -0 -n1 md5sum | sort -k 1,32 | uniq -w 32 -d --all-repeated=separate | sed -e 's/^[0-9a-f]*\ *//;'"
alias testunicode='perl -Mcharnames=:full -CS -wle '\''print "\N{EURO SIGN}"'\'''
alias x='exit'
function _force_rehash() { (( CURRENT == 1 )) && rehash ; return 1 }
function goog; { /usr/bin/links 'http://www.google.com/search?q='${(j:+:)*} }
function google; { /usr/bin/chromium 'http://www.google.com/search?q='${(j:+:)*} }
function h() { if [ -z "$*" ]; then history 1; else history 1 | egrep "$@"; fi; }
#### end aliases and functions #### }
#### tmux shell init #### {
if [[ $USER != root ]]; then
tmux_count=`tmux ls | wc -l`
if [[ "$tmux_count" == "0" ]]; then
tmux -2
else
if [[ -z "$TMUX" ]]; then
if [[ "$tmux_count" == "1" ]]; then
session_id=1
else
session_id=`echo $tmux_count`
fi
tmux -2 new-session -d -s $session_id
tmux -2 attach-session -t $session_id
fi
fi
else
fi
#### tmux init end #### }
#### motd / fortune #### {
fortune futurama
#### end motd / fortune #### }
#### prompt #### {
PS1='%(!.%B%F{red}%n %B%F{blue}[%d] %B%F{red}%{☿%} %b%f%k.%B%F{green}%n@%m%k %B%F{blue}%1~ %# %b%f%k)'
#### end prompt #### }
all the brackets in the comments are for vim folding to make life easier.
on of the cool parts about zsh is the globbing features:
% ls *(
% -- device files
) -- end of qualifiers
* -- executable plain files
+ -- + command name
- -- follow symlinks toggle
. -- plain files
/ -- directories
: -- modifier
= -- sockets
@ -- symbolic links
A -- group-readable
D -- glob dots
E -- group-executable
F -- non-empty directories
G -- owned by EGID
I -- group-writeable
L -- + size
M -- mark directories
N -- use NULL_GLOB
O -- + sort order, down
P -- prepend word
R -- world-readable
S -- setgid
T -- mark types
U -- owned by EUID
W -- world-writeable
X -- world-executable
[ -- + range of files
^ -- negate qualifiers
a -- + access time
c -- + inode change time
d -- + device
e -- execute code
f -- + access rights
g -- + owning group
l -- + link count
m -- + modification time
n -- numeric glob sort
o -- + sort order, up
p -- name pipes (FIFOS)
r -- owner-readable
s -- setuid
t -- sticky bit set
u -- + owning user
w -- owner-writeable
x -- owner-executable
Leave a Reply