1 # Zsh configuration file.
4 # MISCELLANEOUS SETTINGS
6 # Use Vi(m) style key bindings.
9 # Be paranoid, new files are readable/writable by me only.
12 # Make sure core dumps are created.
15 # Prevent overwriting existing files with '> filename', use '>| filename'
19 # Entering the name of a directory (if it's not a command) will automatically
20 # cd to that directory.
23 # When entering a nonexistent command name automatically try to find a similar
27 # Enable zsh's extended glob abilities.
30 # Don't exit if <C-d> is pressed.
36 # Use history and store it in ~/.zsh/history.
39 HISTFILE=~/.zsh/history
40 # Append to the history file instead of overwriting it and do it immediately
41 # when a command is executed.
43 setopt incappendhistory
44 # If the same command is run multiple times store it only once in the history.
46 # Vim like completions of previous executed commands.
47 bindkey "^P" history-beginning-search-backward
48 bindkey "^N" history-beginning-search-forward
53 # Autoload add-zsh-hook to add/remove zsh hook functions easily.
54 autoload -Uz add-zsh-hook
56 # Use colorized output, necessary for prompts and completions.
57 autoload -U colors && colors
59 # Set the default prompt. The current host and working directory is displayed,
60 # the exit code of the last command if it wasn't 0, the number of running jobs
61 # if not 0 and a + if this shell is running inside another shell.
62 # The prompt is in green and blue to make easily detectable, the error exit
63 # code in red and bold and the job count in yellow.
64 PROMPT="%{${fg[green]}%}%B%m%b%{${fg[default]}%}:\
65 %{${fg[blue]}%}%B%~%b%{${fg[default]}%} \
66 %(1j.%{${fg[yellow]}%}%j%{${fg[default]}%}.)%(2L.+.)%# \
67 %(?..(%{${fg[red]}%}%B%?%b%{${fg[default]}%}%) )"
69 # Allow substitutions and expansions in the prompt, necessary for vcs_info.
71 # Load vcs_info to display information about version control repositories.
73 # Only look for git and mercurial repositories; the only I use.
74 zstyle ':vcs_info:*' enable git hg
75 # Set style of vcs_info display. The current branch (green) and vcs (blue) is
76 # displayed. If there is an special action going on (merge, rebase) it's also
78 zstyle ':vcs_info:*' formats \
79 "(%{${fg[green]}%}%b%{${fg[default]}%}:\
80 %{${fg[blue]}%}%s%{${fg[default]}%})"
81 zstyle ':vcs_info:*' actionformats \
82 "(%{${fg[green]}%}%b%{${fg[default]}%}/\
83 %{${fg[red]}%}%a%{${fg[default]}%}:\
84 %{${fg[blue]}%}%s%{${fg[default]}%})"
85 # Call vcs_info as precmd before every prompt.
89 add-zsh-hook precmd prompt_precmd
91 # Display the vcs information in the right prompt.
92 RPROMPT='${vcs_info_msg_0_}'
97 # Use new completion system.
98 autoload -U compinit && compinit
99 # Load the complist module which provides additions to completion lists
100 # (coloring, scrollable).
101 zmodload zsh/complist
102 # Make sure the list of possible completions is displayed after pressing <TAB>
104 setopt nolistambiguous
105 # Allow completions in the middle of a text, i.e. "/usr/bin/<TAB>whatever"
106 # completes like "/usr/bin/<TAB>". Useful when adding new options to commands.
107 bindkey "^I" expand-or-complete-prefix
108 # Use cache to speed up completions.
109 zstyle ':completion:*' use-cache on
110 zstyle ':completion:*' cache-path ~/.zsh/cache
111 # Try uppercase if the currently typed string doesn't match. This allows
112 # typing in lowercase most of the time and completion fixes the case.
113 zstyle ':completion:*' matcher-list '' 'm:{a-z}={A-Z}'
114 # Ignore completion functions.
115 zstyle ':completion:*:functions' ignored-patterns '_*'
116 # Ignore parent directory.
117 zstyle ':completion:*:(cd|mv|cp):*' ignore-parents parent pwd
118 # Use ls like colors for completions.
119 zstyle ':completion:*' list-colors ${(s.:.)LS_COLORS}
120 # Make completion lists scrollable so "do you wish to see all n possibilities"
121 # is no longer displayed.
122 zstyle ':completion:*' list-prompt '%p'
123 # When unsetting variables make sure every variable name is only suggested
125 zstyle ':completion:*:unset:*' ignore-line yes
126 # When working with Mercurial and Git don't complete the same file multiple
127 # times. Very useful when completing file names.
128 zstyle ':completion:*:(hg|git)*:*' ignore-line yes
131 # ALIAS AND FUNCTION SETTINGS
133 # Simplify calls to less, automatically redirects all output.
134 alias -g L='2>&1 | less'
135 # Simplify calls to colordiff, output is also piped through less.
136 alias -g D='2>&1 | colordiff L'
137 # Simplify calls to grep.
140 # Automatically use unified diffs.
143 # Display all files and use human readable sizes.
146 # Multiple files given to Vim are opened in tabs.
152 # Exit binding like in Vim.
155 # Edit the mercurial patch queue series file for the current mercurial
156 # repository in Vim. Also change Vim's pwd to the patches directory so other
157 # patches can easily be opened.
158 alias vqs='vim -c "cd $(hg root)/.hg/patches/" "$(hg root)/.hg/patches/series"'
160 # Make going up directories simple.
162 alias -g ....='../../..'
164 # Improved ls which displays the files in columns (-C), visualizes directories,
165 # links and other special files (-F) and pages everything through less (L).
167 # If available use GNU ls with colorized output. If it isn't available use
168 # normal ls which needs CLICOLOR_FORCE so it displays colors when used with a
170 ls --color &> /dev/null
171 if [[ $? -eq 0 ]]; then
172 alias ls='ls --color'
174 alias ls='CLICOLOR_FORCE=1 ls -G'
178 command ls -C -F $* L
180 # Helper function to list all files.
184 # Helper function to list all files in list format with access rights, etc.
189 # If ^C is pressed while typing a command, add it to the history so it can be
190 # easily retrieved later and then abort like ^C normally does. This is useful
191 # when I want to abort an command to do something in between and then finish
192 # typing the command.
194 # Store the current buffer in the history.
195 zle && print -s $BUFFER
197 # Return the default exit code so zsh aborts the current command.
201 # Execute all periodic functions every hour.
203 # Display TODOs stored in ~/.todo if this file exists. Run every hour to make
204 # clear they should be completed ;-).
206 if [[ -f ~/.todo ]]; then
210 add-zsh-hook periodic todo
213 # Load rc file for current OS.
214 source_config ~/.zsh os rc $(uname) nolocal
215 # Load rc file for current hostname (first part before a dot) or rc.local.
216 source_config ~/.zsh host rc ${$(hostname)//.*/}