]> ruderich.org/simon Gitweb - config/dotfiles.git/blob - zsh/rc
9b42bd102848da812253495902a5aa12607c347a
[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, necessary for prompts and completions.
33 autoload -U colors && colors
34
35 # Set the default prompt. The current host and working directory is displayed,
36 # the exit code of the last command if it wasn't 0 and a + if this shell is
37 # running inside another shell.
38 # The prompt is in green and blue to make easily detectable, the error exit
39 # code in red and bold.
40 PROMPT="%{${fg[green]}%}%B%m%b%{${fg[default]}%}:\
41 %{${fg[blue]}%}%B%~%b%{${fg[default]}%} %(2L.+.)%# \
42 %(?..(%{${fg[red]}%}%B%?%b%{${fg[default]}%}%) )"
43
44 # Use new completion system.
45 autoload -U compinit && compinit
46 # Load the complist module which provides additions to completion lists
47 # (coloring, scrollable).
48 zmodload zsh/complist
49 # Make sure the list of possible completions is displayed after pressing <TAB>
50 # the first time.
51 setopt nolistambiguous
52 # Allow completions in the middle of a text, i.e. "/usr/bin/<TAB>whatever"
53 # completes like "/usr/bin/<TAB>". Useful when adding new options to commands.
54 bindkey "^I" expand-or-complete-prefix
55 # Use cache to speed up completions.
56 zstyle ':completion:*' use-cache on
57 zstyle ':completion:*' cache-path ~/.zsh/cache
58 # Ignore case if currently typed string doesn't match.
59 zstyle ':completion:*' matcher-list '' 'm:{a-zA-Z}={A-Za-z}'
60 # Ignore completion functions.
61 zstyle ':completion:*:functions' ignored-patterns '_*'
62 # Ignore parent directory.
63 zstyle ':completion:*:(cd|mv|cp):*' ignore-parents parent pwd
64 # Use ls like colors for completions.
65 zstyle ':completion:*' list-colors ${(s.:.)LS_COLORS}
66 # Make completion lists scrollable so "do you wish to see all n possibilities"
67 # is no longer displayed.
68 zstyle ':completion:*' list-prompt '%p'
69
70 # Enable zsh's extended glob abilities.
71 setopt extendedglob
72
73 # If ^C is pressed while typing a command, add it to the history so it can be
74 # easily retrieved later and then abort like ^C normally does. This is useful
75 # when I want to abort an command to do something in between and then finish
76 # typing the command.
77 TRAPINT() {
78     # Store the current buffer in the history.
79     zle && print -s $BUFFER
80
81     # Return the default exit code so zsh aborts the current command.
82     return $1
83 }
84
85 # Simplify calls to less, automatically redirects all output.
86 alias -g L='2>&1 | less'
87 # Simplify calls to colordiff, output is also piped through less.
88 alias -g D='2>&1 | colordiff L'
89 # Simplify calls to grep.
90 alias -g G='| grep'
91
92 # Improved ls which displays the files in columns (-C), visualises directories,
93 # links and other special files (-F) and pages everything through less (L).
94 function ls() {
95     command ls -C -F $* L
96 }
97 # Helper function to list all files.
98 function la() {
99     ls -a $*
100 }
101 # Helper function to list all files in list format with access rights, etc.
102 function ll() {
103     la -l $*
104 }
105
106
107 # If a rc file for the current hostname (first part before a dot) exists load
108 # it, otherwise load rc.local if available.
109 host=${$(hostname)//.*/}
110 if [[ -f ~/.zsh/rc.$host ]]; then;
111     source ~/.zsh/rc.$host
112 elif [[ -f ~/.zsh/rc.local ]]; then;
113     source ~/.zsh/rc.local
114 fi