1 # Zsh configuration file.
4 source_debug "sourcing ~/.zsh/rc"
6 # MISCELLANEOUS SETTINGS
8 # Use Vi(m) style key bindings.
11 # Be paranoid, new files are readable/writable by me only.
14 # Make sure core dumps are created.
17 # Prevent overwriting existing files with '> filename', use '>| filename'
21 # Entering the name of a directory (if it's not a command) will automatically
22 # cd to that directory.
25 # When entering a nonexistent command name automatically try to find a similar
29 # Enable zsh's extended glob abilities.
32 # Don't exit if <C-d> is pressed.
38 # Set correct fpath to allow loading my functions (including completion
40 fpath=(~/.zsh/functions $fpath)
41 # Autoload my functions (except completion functions and hidden files). Thanks
42 # to caphuso from the Zsh example files for this idea.
43 autoload ${fpath[1]}/^_*(^/:t)
45 # Autoload add-zsh-hook to add/remove zsh hook functions easily.
46 autoload -Uz add-zsh-hook
51 # Use history and store it in ~/.zsh/history.
54 HISTFILE=~/.zsh/history
55 # Append to the history file instead of overwriting it and do it immediately
56 # when a command is executed.
58 setopt incappendhistory
59 # If the same command is run multiple times store it only once in the history.
61 # Vim like completions of previous executed commands.
62 bindkey "^P" history-beginning-search-backward
63 bindkey "^N" history-beginning-search-forward
68 # Use colorized output, necessary for prompts and completions.
69 autoload -U colors && colors
71 # Set the default prompt. The current host and working directory is displayed,
72 # the exit code of the last command if it wasn't 0, the number of running jobs
73 # if not 0 and a + if this shell is running inside another shell.
74 # The prompt is in green and blue to make easily detectable, the error exit
75 # code in red and bold and the job count in yellow.
76 PROMPT="%{${fg[green]}%}%B%m%b%{${fg[default]}%}:\
77 %{${fg[blue]}%}%B%~%b%{${fg[default]}%} \
78 %(1j.%{${fg[yellow]}%}%j%{${fg[default]}%}.)%(2L.+.)%# \
79 %(?..(%{${fg[red]}%}%B%?%b%{${fg[default]}%}%) )"
81 # VCS_Info was added in 4.3.9.
82 if [[ $ZSH_VERSION == (4.3.<9->|4.<4->*|<5->*) ]]; then
83 # Allow substitutions and expansions in the prompt, necessary for
86 # Load vcs_info to display information about version control repositories.
88 # Only look for git and mercurial repositories; the only I use.
89 zstyle ':vcs_info:*' enable git hg
90 # Set style of vcs_info display. The current branch (green) and vcs (blue)
91 # is displayed. If there is an special action going on (merge, rebase)
92 # it's also displayed (red).
93 zstyle ':vcs_info:*' formats \
94 "(%{${fg[green]}%}%b%{${fg[default]}%}:\
95 %{${fg[blue]}%}%s%{${fg[default]}%})"
96 zstyle ':vcs_info:*' actionformats \
97 "(%{${fg[green]}%}%b%{${fg[default]}%}/\
98 %{${fg[red]}%}%a%{${fg[default]}%}:\
99 %{${fg[blue]}%}%s%{${fg[default]}%})"
100 # Call vcs_info as precmd before every prompt.
104 add-zsh-hook precmd prompt_precmd
106 # Display the vcs information in the right prompt.
107 RPROMPT='${vcs_info_msg_0_}'
110 # When screen is used set the name of the window to the currently running
113 # When a program is started preexec() sets the window's name to it; when it
114 # stops precmd() resets the windows' name to 'zsh'.
115 if [[ $TERM == screen ]]; then
116 # Set to a non empty value to reset the window name in the next precmd()
118 screen_name_reset=yes
121 # Get the program name with its arguments.
122 local program_name=$1
123 # When sudo is used use real program name instead.
124 if [[ $program_name == sudo* ]]; then
125 program_name=${program_name#sudo }
127 # Remove all arguments from the program name.
128 program_name=${program_name%% *}
130 # Ignore often used commands which are only running for a very short
131 # time. This prevents a "blinking" name when it's changed to "cd" for
132 # example and then some milliseconds later back to "zsh".
133 [[ $program_name == (cd*|ls|la|ll|clear) ]] && return
135 # Change my shortcuts so the real name of the program is displayed.
136 case $program_name in
151 # Set the window name to the currently running program.
152 print -n "\ek$program_name\e\\"
154 # Tell precmd() to reset the window name when the program stops.
155 screen_name_reset=yes
159 # Abort if no window name reset is necessary.
160 [[ -z $screen_name_reset ]] && return
162 # Reset the window name to 'zsh'.
163 print -n "\ekzsh\e\\"
165 # Just reset the name, so no screen reset necessary for the moment.
169 # Add the preexec() and precmd() hooks.
170 add-zsh-hook preexec screen_preexec
171 add-zsh-hook precmd screen_precmd
175 # COMPLETION SETTINGS
177 # Load the complist module which provides additions to completion lists
178 # (coloring, scrollable).
179 zmodload zsh/complist
180 # Use new completion system, store dumpfile in ~/.zsh/cache to prevent
182 autoload -U compinit && compinit -d ~/.zsh/cache/zcompdump
183 # Make sure the list of possible completions is displayed after pressing <TAB>
185 setopt nolistambiguous
186 # Allow completions in the middle of a text, i.e. "/usr/bin/<TAB>whatever"
187 # completes like "/usr/bin/<TAB>". Useful when adding new options to commands.
188 bindkey "^I" expand-or-complete-prefix
189 # Use cache to speed up completions.
190 zstyle ':completion:*' use-cache on
191 zstyle ':completion:*' cache-path ~/.zsh/cache
192 # Try uppercase if the currently typed string doesn't match. This allows
193 # typing in lowercase most of the time and completion fixes the case.
194 zstyle ':completion:*' matcher-list '' 'm:{a-z}={A-Z}'
195 # Ignore completion functions.
196 zstyle ':completion:*:functions' ignored-patterns '_*'
197 # Ignore parent directory.
198 zstyle ':completion:*:(cd|mv|cp):*' ignore-parents parent pwd
199 # Use ls like colors for completions.
200 zstyle ':completion:*' list-colors ${(s.:.)LS_COLORS}
201 # Make completion lists scrollable so "do you wish to see all n possibilities"
202 # is no longer displayed.
203 zstyle ':completion:*' list-prompt '%p'
204 # When unsetting variables make sure every variable name is only suggested
206 zstyle ':completion:*:unset:*' ignore-line yes
207 # When working with Mercurial and Git don't complete the same file multiple
208 # times. Very useful when completing file names.
209 zstyle ':completion:*:(hg|git)*:*' ignore-line yes
212 # CUSTOM ALIASES AND FUNCTIONS
214 # Simplify calls to less, automatically redirects all output.
215 alias -g L='2>&1 | less'
216 # Simplify calls to colordiff, output is also piped through less.
217 alias -g D='2>&1 | colordiff L'
218 # Simplify calls to grep.
221 # Automatically use unified diffs.
224 # Display all files and use human readable sizes.
227 # Multiple files given to Vim are opened in tabs, supported since Vim 7.
228 if [[ ${${${(f)"$(vim --version)"}[1]#VIM - Vi IMproved }%% *} == 7* ]]; then
232 # Shortcuts for often used programs.
239 # Exit binding like in Vim; I sometimes confuse editor and shell.
242 # Edit the mercurial patch queue series file for the current mercurial
243 # repository in Vim. Also change Vim's pwd to the patches directory so other
244 # patches can easily be opened.
245 alias vqs='vim -c "cd $(hg root)/.hg/patches/" "$(hg root)/.hg/patches/series"'
247 # Make going up directories simple.
249 alias -g ....='../../..'
250 alias -g .....='../../../..'
252 # Improved ls which displays the files in columns (-C), visualizes directories,
253 # links and other special files (-F) and pages everything through less (L).
255 # If available use GNU ls with colorized output. If it isn't available use
256 # normal ls which needs CLICOLOR_FORCE so it displays colors when used with a
258 ls --color &> /dev/null
259 if [[ $? -eq 0 ]]; then
260 alias ls='ls --color'
262 alias ls='CLICOLOR_FORCE=1 ls -G'
266 command ls -C -F $* L
268 # Helper function to list all files.
272 # Helper function to list all files in list format with access rights, etc.
277 # If ^C is pressed while typing a command, add it to the history so it can be
278 # easily retrieved later and then abort like ^C normally does. This is useful
279 # when I want to abort an command to do something in between and then finish
280 # typing the command.
282 # Store the current buffer in the history.
283 zle && print -s $BUFFER
285 # Return the default exit code so zsh aborts the current command.
289 # Display TODOs stored in ~/.todo if this file exists.
291 if [[ -f ~/.todo ]]; then
297 # Load rc file for current OS.
298 source_config ~/.zsh os rc $(uname) nolocal
299 # Load rc file for current hostname (first part before a dot) or rc.local.
300 source_config ~/.zsh host rc ${$(hostname)//.*/}
302 source_debug "finished sourcing ~/.zsh/rc"