]> ruderich.org/simon Gitweb - config/dotfiles.git/blob - zsh/rc
aa24736f255ff9601af685db50807ff0cecd9c99
[config/dotfiles.git] / zsh / rc
1 # Zsh configuration file.
2
3
4 # MISCELLANEOUS SETTINGS
5
6 # Use Vi(m) style key bindings.
7 bindkey -v
8
9 # Be paranoid, new files are readable/writable by me only.
10 umask 077
11
12 # Make sure core dumps are created.
13 ulimit -c unlimited
14
15 # Prevent overwriting existing files with '> filename', use '>| filename'
16 # (or >!) instead.
17 setopt noclobber
18
19 # Entering the name of a directory (if it's not a command) will automatically
20 # cd to that directory.
21 setopt autocd
22
23 # When entering a nonexistent command name automatically try to find a similar
24 # one.
25 setopt correct
26
27 # Enable zsh's extended glob abilities.
28 setopt extendedglob
29
30 # Don't exit if <C-d> is pressed.
31 setopt ignoreeof
32
33
34 # HISTORY SETTINGS
35
36 # Use history and store it in ~/.zsh/history.
37 HISTSIZE=1000
38 SAVEHIST=1000
39 HISTFILE=~/.zsh/history
40 # Append to the history file instead of overwriting it and do it immediately
41 # when a command is executed.
42 setopt appendhistory
43 setopt incappendhistory
44 # If the same command is run multiple times store it only once in the history.
45 setopt histignoredups
46 # Vim like completions of previous executed commands.
47 bindkey "^P" history-beginning-search-backward
48 bindkey "^N" history-beginning-search-forward
49
50
51 # PROMPT SETTINGS
52
53 # Autoload add-zsh-hook to add/remove zsh hook functions easily.
54 autoload -Uz add-zsh-hook
55
56 # Use colorized output, necessary for prompts and completions.
57 autoload -U colors && colors
58
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]}%}%) )"
68
69
70 # COMPLETION SETTINGS
71
72 # Use new completion system.
73 autoload -U compinit && compinit
74 # Load the complist module which provides additions to completion lists
75 # (coloring, scrollable).
76 zmodload zsh/complist
77 # Make sure the list of possible completions is displayed after pressing <TAB>
78 # the first time.
79 setopt nolistambiguous
80 # Allow completions in the middle of a text, i.e. "/usr/bin/<TAB>whatever"
81 # completes like "/usr/bin/<TAB>". Useful when adding new options to commands.
82 bindkey "^I" expand-or-complete-prefix
83 # Use cache to speed up completions.
84 zstyle ':completion:*' use-cache on
85 zstyle ':completion:*' cache-path ~/.zsh/cache
86 # Try uppercase if the currently typed string doesn't match. This allows
87 # typing in lowercase most of the time and completion fixes the case.
88 zstyle ':completion:*' matcher-list '' 'm:{a-z}={A-Z}'
89 # Ignore completion functions.
90 zstyle ':completion:*:functions' ignored-patterns '_*'
91 # Ignore parent directory.
92 zstyle ':completion:*:(cd|mv|cp):*' ignore-parents parent pwd
93 # Use ls like colors for completions.
94 zstyle ':completion:*' list-colors ${(s.:.)LS_COLORS}
95 # Make completion lists scrollable so "do you wish to see all n possibilities"
96 # is no longer displayed.
97 zstyle ':completion:*' list-prompt '%p'
98 # When unsetting variables make sure every variable name is only suggested
99 # once.
100 zstyle ':completion:*:unset:*' ignore-line yes
101 # When working with mercurial don't complete the same file multiple times.
102 zstyle ':completion:*:hg*:*' ignore-line yes
103
104
105 # ALIAS AND FUNCTION SETTINGS
106
107 # Simplify calls to less, automatically redirects all output.
108 alias -g L='2>&1 | less'
109 # Simplify calls to colordiff, output is also piped through less.
110 alias -g D='2>&1 | colordiff L'
111 # Simplify calls to grep.
112 alias -g G='| grep'
113
114 # Automatically use unified diffs.
115 alias diff='diff -u'
116
117 # Display all files and use human readable sizes.
118 alias du='du -sh'
119
120 # Multiple files given to Vim are opened in tabs.
121 alias vim='vim -p'
122 # Shortcuts for Vim.
123 alias v='vim'
124 alias vi='vim'
125
126 # Exit binding like in Vim.
127 alias :q='exit'
128
129 # Edit the mercurial patch queue series file for the current mercurial
130 # repository in Vim. Also change Vim's pwd to the patches directory so other
131 # patches can easily be opened.
132 alias vqs='vim -c "cd $(hg root)/.hg/patches/" "$(hg root)/.hg/patches/series"'
133
134 # Make going up directories simple.
135 alias -g ...='../..'
136 alias -g ....='../../..'
137
138 # Improved ls which displays the files in columns (-C), visualizes directories,
139 # links and other special files (-F) and pages everything through less (L).
140 #
141 # If available use GNU ls with colorized output. If it isn't available use
142 # normal ls which needs CLICOLOR_FORCE so it displays colors when used with a
143 # pager.
144 ls --color &> /dev/null
145 if [[ $? -eq 0 ]]; then
146     alias ls='ls --color'
147 else
148     alias ls='CLICOLOR_FORCE=1 ls -G'
149 fi
150 # Main ls function.
151 function ls() {
152     command ls -C -F $* L
153 }
154 # Helper function to list all files.
155 function la() {
156     ls -a $*
157 }
158 # Helper function to list all files in list format with access rights, etc.
159 function ll() {
160     la -l $*
161 }
162
163 # If ^C is pressed while typing a command, add it to the history so it can be
164 # easily retrieved later and then abort like ^C normally does. This is useful
165 # when I want to abort an command to do something in between and then finish
166 # typing the command.
167 TRAPINT() {
168     # Store the current buffer in the history.
169     zle && print -s $BUFFER
170
171     # Return the default exit code so zsh aborts the current command.
172     return $1
173 }
174
175 # Execute all periodic functions every hour.
176 PERIOD=3600
177 # Display TODOs stored in ~/.todo if this file exists. Run every hour to make
178 # clear they should be completed ;-).
179 todo() {
180     if [[ -f ~/.todo ]]; then
181         cat ~/.todo | $PAGER
182     fi
183 }
184 add-zsh-hook periodic todo
185
186
187 # Load rc file for current OS.
188 source_config ~/.zsh os rc $(uname) nolocal
189 # Load rc file for current hostname (first part before a dot) or rc.local.
190 source_config ~/.zsh host rc ${$(hostname)//.*/}