]> ruderich.org/simon Gitweb - config/dotfiles.git/blob - zsh/rc
First load the zsh file for this hostname, then (env|rc).local.
[config/dotfiles.git] / zsh / rc
1 # Zsh configuration file.
2
3
4 # Use Vi(m) style key bindings.
5 bindkey -v
6
7 # Use history and store it in ~/.zsh/history.
8 HISTSIZE=1000
9 SAVEHIST=1000
10 HISTFILE=~/.zsh/history
11 # Append to the history file instead of overwriting it and do it immediately
12 # when a command is executed.
13 setopt appendhistory
14 setopt incappendhistory
15 # If the same command is run multiple times store it only once in the history.
16 setopt histignoredups
17 # Vim like completions of previous executed commands.
18 bindkey "^P" history-beginning-search-backward
19 bindkey "^N" history-beginning-search-forward
20
21 # Prevent overwriting existing files with '> filename'.
22 setopt noclobber
23
24 # Entering the name of a directory (if it's not a command) will automatically
25 # cd to that directory.
26 setopt autocd
27
28 # When entering a nonexistent command name automatically try to find a similar
29 # one.
30 setopt correct
31
32 # Use colorized output.
33 autoload -U colors && colors
34 # Set the default prompt. The current host and working directory is displayed,
35 # the exit code of the last command if it wasn't 0 and a + if this shell is
36 # running inside another shell.
37 # The prompt is in green and blue to make easily detectable, the error exit
38 # code in red and bold.
39 PROMPT="%{${fg[green]}%}%B%m%b%{${fg[default]}%}:\
40 %{${fg[blue]}%}%B%~%b%{${fg[default]}%} %(2L.+.)%# \
41 %(?..(%{${fg[red]}%}%B%?%b%{${fg[default]}%}%) )"
42
43 # Use new completion system.
44 autoload -U compinit && compinit
45 # Make sure the list of possible completions is displayed after pressing <TAB>
46 # the first time.
47 setopt nolistambiguous
48 # Allow completions in the middle of a text, i.e. "/usr/bin/<TAB>whatever"
49 # completes like "/usr/bin/<TAB>". Useful when adding new options to commands.
50 bindkey "^I" expand-or-complete-prefix
51 # Use cache to speed up completions.
52 zstyle ':completion:*' use-cache on
53 zstyle ':completion:*' cache-path ~/.zsh/cache
54 # Ignore case if currently typed string doesn't match.
55 zstyle ':completion:*' matcher-list '' 'm:{a-zA-Z}={A-Za-z}'
56 # Ignore completion functions.
57 zstyle ':completion:*:functions' ignored-patterns '_*'
58 # Ignore parent directory.
59 zstyle ':completion:*:(cd|mv|cp):*' ignore-parents parent pwd
60
61 # Enable zsh's extended glob abilities.
62 setopt extendedglob
63
64 # If ^C is pressed while typing a command, add it to the history so it can be
65 # easily retrieved later and then abort like ^C normally does. This is useful
66 # when I want to abort an command to do something in between and then finish
67 # typing the command.
68 TRAPINT() {
69     # Store the current buffer in the history.
70     zle && print -s $BUFFER
71
72     # Return the default exit code so zsh aborts the current command.
73     return $1
74 }
75
76 # Simplify calls to less, automatically redirects all output.
77 alias -g L='2>&1 | less'
78 # Simplify calls to colordiff, output is also piped through less.
79 alias -g D='2>&1 | colordiff L'
80 # Simplify calls to grep.
81 alias -g G='| grep'
82
83 # Improved ls which displays the files in columns (-C), visualises directories,
84 # links and other special files (-F) and pages everything through less (L).
85 function ls() {
86     command ls -C -F $* L
87 }
88 # Helper function to list all files.
89 function la() {
90     ls -a $*
91 }
92 # Helper function to list all files in list format with access rights, etc.
93 function ll() {
94     la -l $*
95 }
96
97
98 # If a rc file for the current hostname (first part before a dot) exists load
99 # it, otherwise load rc.local if available.
100 host=${$(hostname)//.*/}
101 if [[ -f ~/.zsh/rc.$host ]]; then;
102     source ~/.zsh/rc.$host
103 elif [[ -f ~/.zsh/rc.local ]]; then;
104     source ~/.zsh/rc.local
105 fi