1 # Zsh configuration file.
4 # Use Vi(m) style key bindings.
7 # Be paranoid, new files are readable/writable by me only.
10 # Use history and store it in ~/.zsh/history.
13 HISTFILE=~/.zsh/history
14 # Append to the history file instead of overwriting it and do it immediately
15 # when a command is executed.
17 setopt incappendhistory
18 # If the same command is run multiple times store it only once in the history.
20 # Vim like completions of previous executed commands.
21 bindkey "^P" history-beginning-search-backward
22 bindkey "^N" history-beginning-search-forward
24 # Prevent overwriting existing files with '> filename', use '>| filename'
28 # Entering the name of a directory (if it's not a command) will automatically
29 # cd to that directory.
32 # When entering a nonexistent command name automatically try to find a similar
36 # Use colorized output, necessary for prompts and completions.
37 autoload -U colors && colors
39 # Set the default prompt. The current host and working directory is displayed,
40 # the exit code of the last command if it wasn't 0, the number of running jobs
41 # if not 0 and a + if this shell is running inside another shell.
42 # The prompt is in green and blue to make easily detectable, the error exit
43 # code in red and bold and the job count in yellow.
44 PROMPT="%{${fg[green]}%}%B%m%b%{${fg[default]}%}:\
45 %{${fg[blue]}%}%B%~%b%{${fg[default]}%} \
46 %(1j.%{${fg[yellow]}%}%j%{${fg[default]}%}.)%(2L.+.)%# \
47 %(?..(%{${fg[red]}%}%B%?%b%{${fg[default]}%}%) )"
49 # Use new completion system.
50 autoload -U compinit && compinit
51 # Load the complist module which provides additions to completion lists
52 # (coloring, scrollable).
54 # Make sure the list of possible completions is displayed after pressing <TAB>
56 setopt nolistambiguous
57 # Allow completions in the middle of a text, i.e. "/usr/bin/<TAB>whatever"
58 # completes like "/usr/bin/<TAB>". Useful when adding new options to commands.
59 bindkey "^I" expand-or-complete-prefix
60 # Use cache to speed up completions.
61 zstyle ':completion:*' use-cache on
62 zstyle ':completion:*' cache-path ~/.zsh/cache
63 # Try uppercase if the currently typed string doesn't match. This allows
64 # typing in lowercase most of the time and completion fixes the case.
65 zstyle ':completion:*' matcher-list '' 'm:{a-z}={A-Z}'
66 # Ignore completion functions.
67 zstyle ':completion:*:functions' ignored-patterns '_*'
68 # Ignore parent directory.
69 zstyle ':completion:*:(cd|mv|cp):*' ignore-parents parent pwd
70 # Use ls like colors for completions.
71 zstyle ':completion:*' list-colors ${(s.:.)LS_COLORS}
72 # Make completion lists scrollable so "do you wish to see all n possibilities"
73 # is no longer displayed.
74 zstyle ':completion:*' list-prompt '%p'
75 # When unsetting variables make sure every variable name is only suggested
77 zstyle ':completion:*:unset:*' ignore-line yes
78 # When working with mercurial don't complete the same file multiple times.
79 zstyle ':completion:*:hg*:*' ignore-line yes
81 # Enable zsh's extended glob abilities.
84 # Don't exit if <C-d> is pressed.
87 # If ^C is pressed while typing a command, add it to the history so it can be
88 # easily retrieved later and then abort like ^C normally does. This is useful
89 # when I want to abort an command to do something in between and then finish
92 # Store the current buffer in the history.
93 zle && print -s $BUFFER
95 # Return the default exit code so zsh aborts the current command.
99 # Simplify calls to less, automatically redirects all output.
100 alias -g L='2>&1 | less'
101 # Simplify calls to colordiff, output is also piped through less.
102 alias -g D='2>&1 | colordiff L'
103 # Simplify calls to grep.
106 # Automatically use unified diffs.
109 # Display all files and use human readable sizes.
112 # Multiple files given to Vim are opened in tabs.
118 # Exit binding like in Vim.
121 # Edit the mercurial patch queue series file for the current mercurial
122 # repository in Vim. Also change Vim's pwd to the patches directory so other
123 # patches can easily be opened.
124 alias vqs='vim -c "cd $(hg root)/.hg/patches/" "$(hg root)/.hg/patches/series"'
126 # Make going up directories simple.
128 alias -g ....='../../..'
130 # Improved ls which displays the files in columns (-C), visualises directories,
131 # links and other special files (-F) and pages everything through less (L).
133 # If available use GNU ls with colorized output. If it isn't available use
134 # normal ls which needs CLICOLOR_FORCE so it displays colors when used with a
136 ls --color &> /dev/null
137 if [[ $? -eq 0 ]]; then
138 alias ls='ls --color'
140 alias ls='CLICOLOR_FORCE=1 ls -G'
144 command ls -C -F $* L
146 # Helper function to list all files.
150 # Helper function to list all files in list format with access rights, etc.
156 # Load rc file for current OS.
157 source_config ~/.zsh os rc $(uname) nolocal
158 # Load rc file for current hostname (first part before a dot) or rc.local.
159 source_config ~/.zsh host rc ${$(hostname)//.*/}