Text only
18 Mar 2010
 

~/.zshrc

 
Tools: wrap/unwrap  
  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
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
#===============================================================================
#
# ~/.zshrc
# Written by Minoru (eual.jp@gmail.com)
#
# DEPENDENCIES:
# ~/.dir_colors
#
# zsh 4.3.10
#
#===============================================================================
#-------------------------------------------------------------------------------
#
# HISTORY
#
# History file
HISTFILE=~/.zhistory
# The number of lines the shell will keep within one session
HISTSIZE=10240
# The number of lines of history will be saved
SAVEHIST=8192
# All running zsh sessions will have exactly the same history
# Don't worry - '!' command and so will work only with current session's history
setopt SHARE_HISTORY
# Remove all duplicates of current command from history, add current to end
setopt HIST_IGNORE_ALL_DUPS
# Don't save any commands beginning with space
setopt HIST_IGNORE_SPACE
# Don't save 'history' and 'fc' commands
setopt HIST_NO_STORE
#-------------------------------------------------------------------------------
#
# PROMPT
#
# Load and initialize colors - we will use it soon
autoload colors && colors
# Prompt on the left is % if regular user or # if root
PROMPT="%{$fg[green]%}%# %{$reset_color%}"
# if connected via ssh, make prompt red
[[ -n ${SSH_CONNECTION} ]] && PROMPT="%{$fg[red]%}%# %{$reset_color%}"
# Prompt on the right is current directory (green font)
RPROMPT="%{$fg[green]%}%~%{$reset_color%}"
#-------------------------------------------------------------------------------
#
# ALIASES
#
# NOTE: if you don't want an alias to be used (for example, you went just 'du',
# but alias is 'du -h') you have two ways:
# - use full path to binaries (continuing example above, it will look like
# '/bin/du')
# - use 'noglob' before command name (e.g., 'noglob du')
# Regular aliases
alias ls="ls -lF --color"
alias l="ls"
alias sl="ls"
alias lsa="ls -a"
alias bzip2='bzip2 -vv --best'
alias bunzip2='bunzip2 -vv'
alias gzip='gzip --best -v'
alias gunzip='gunzip -v'
alias less='less -R'
alias feh='feh -F'
# Some nocorrect aliases (needed only if CORRECT is set)
alias df='nocorrect df -h'
alias du='nocorrect du -h'
alias mv='nocorrect mv -i'
alias cp='nocorrect cp -i'
alias rm='nocorrect rm -i'
alias vim='nocorrect vim'
alias mc='nocorrect mc'
alias mkdir='nocorrect mkdir -p'
# You need run-help module to be loaded to have 'run-help' command
# See MISCELLANEOUS section below
alias help="run-help"
# Some more complicated but still useful aliases
# Start x; works only if user aren't root and command given from tty
#alias x='if [[ $UID != 0 && $TERM == "linux" ]]; then rm -f ~/.xsession-errors; startx; else echo "You are not allowed to start X session"; fi'
if [ "$TERM" = "linux" ]; then
alias mplayer='mplayer -vo fbdev2'
fi
# Suffix aliases for easier files processing
# PDF
alias -s pdf=evince
# FB 2.1
alias -s fb2=fbless
alias -s fb2.bz2=fbless
# DejaVu
alias -s djvu=evince
#-------------------------------------------------------------------------------
#
# FUNCTIONS
#
# This code will change terminal emulator's title
# As far as this action makes sense only in X terminal (and screen, but I don't
# use it), case used for checking are we in X terminal or where
# NOTE: if we're in the tty, $TERM will be "linux"
case $TERM in
xterm* | rxvt*)
# Precmd is called just before the prompt is printed
precmd() {
print -Pn "\e]0;zsh\a"
}
# Preexec is called just before any command line is executed
# $1 is command name
# sed used to cut off parameters of command
preexec() {
print -Pn "\e]0;`echo $1 | head -n1 | sed -r 's/^(sudo [^[:space:]]+|[^[:space:]]+).*/\1/'`\a"
}
# There are postexec too, but I don't need it as far as I configured precmd
;;
esac
function mcd() {
# Create directory and cd to it
mkdir -p "$1" && cd "$1"
}
function lcd() {
# cd to directory and do ls
cd "$1" && ls
}
#-------------------------------------------------------------------------------
#
# MISCELLANEOUS
#
# Don't beep even if zsh don't like something
setopt NO_BEEP
# Change directory even if user forgot to put 'cd' command in front, but entered
# path is valid
setopt AUTO_CD
# If possible, correct commands
setopt CORRECT
# Colors for ls
# When moving this to other machine, don't forget to keep ~/.dir_colors - some
# interesting things there, such as black-at-white setting for showing names of
# directories
eval `dircolors ~/.dir_colors`
zstyle ':completion:*:default' list-colors ${(s.:.)LS_COLORS}
# Making things like "{1-3}" and "{a-d}" working (it expands to "1 2 3" and "a b
# c d")
setopt BRACECCL
# All files created by zsh (it happens when you use redirection of command's
# output to non-existent file) will have ug+rwX,o-rwx (or 750 for directories
# and 640 for files) perrmissions
umask 0027
# Load help system, which can show parts of man pages where specified command
# described. Also, add help="run-help" alias (see above in ALIASES section)
autoload run-help
# key bindings
# needed when connected by ssh, don't hurt if you're connected locally
bindkey "\e[1~" beginning-of-line
bindkey "\e[4~" end-of-line
bindkey "\e[5~" beginning-of-history
bindkey "\e[6~" end-of-history
bindkey "\e[3~" delete-char
#bindkey "\e[2~" quoted-insert
bindkey "\e[5C" forward-word
bindkey "\e[5D" backward-word
bindkey "\e\e[C" forward-word
# for urxvt
bindkey "\e[8~" end-of-line
bindkey "\e[7~" beginning-of-line
#-------------------------------------------------------------------------------
#
# COMPLETION
#
# Sets autocompletion
autoload -Uz compinit && compinit