]> ruderich.org/simon Gitweb - config/dotfiles.git/blob - zsh/rc
e7d243afbe7648004ba6b48291a669e26af7534c
[config/dotfiles.git] / zsh / rc
1 # Zsh configuration file.
2
3
4 # Use Vi(m) style key bindings.
5 bindkey -v
6
7 # Be paranoid, new files are readable/writable by me only.
8 umask 077
9
10 # Use history and store it in ~/.zsh/history.
11 HISTSIZE=1000
12 SAVEHIST=1000
13 HISTFILE=~/.zsh/history
14 # Append to the history file instead of overwriting it and do it immediately
15 # when a command is executed.
16 setopt appendhistory
17 setopt incappendhistory
18 # If the same command is run multiple times store it only once in the history.
19 setopt histignoredups
20 # Vim like completions of previous executed commands.
21 bindkey "^P" history-beginning-search-backward
22 bindkey "^N" history-beginning-search-forward
23
24 # Prevent overwriting existing files with '> filename', use '>| filename'
25 # (or >!) instead.
26 setopt noclobber
27
28 # Entering the name of a directory (if it's not a command) will automatically
29 # cd to that directory.
30 setopt autocd
31
32 # When entering a nonexistent command name automatically try to find a similar
33 # one.
34 setopt correct
35
36 # Use colorized output, necessary for prompts and completions.
37 autoload -U colors && colors
38
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]}%}%) )"
48
49 # Use new completion system.
50 autoload -U compinit && compinit
51 # Load the complist module which provides additions to completion lists
52 # (coloring, scrollable).
53 zmodload zsh/complist
54 # Make sure the list of possible completions is displayed after pressing <TAB>
55 # the first time.
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 # Ignore case if currently typed string doesn't match.
64 zstyle ':completion:*' matcher-list '' 'm:{a-zA-Z}={A-Za-z}'
65 # Ignore completion functions.
66 zstyle ':completion:*:functions' ignored-patterns '_*'
67 # Ignore parent directory.
68 zstyle ':completion:*:(cd|mv|cp):*' ignore-parents parent pwd
69 # Use ls like colors for completions.
70 zstyle ':completion:*' list-colors ${(s.:.)LS_COLORS}
71 # Make completion lists scrollable so "do you wish to see all n possibilities"
72 # is no longer displayed.
73 zstyle ':completion:*' list-prompt '%p'
74
75 # Enable zsh's extended glob abilities.
76 setopt extendedglob
77
78 # Don't exit if <C-d> is pressed.
79 setopt ignoreeof
80
81 # If ^C is pressed while typing a command, add it to the history so it can be
82 # easily retrieved later and then abort like ^C normally does. This is useful
83 # when I want to abort an command to do something in between and then finish
84 # typing the command.
85 TRAPINT() {
86     # Store the current buffer in the history.
87     zle && print -s $BUFFER
88
89     # Return the default exit code so zsh aborts the current command.
90     return $1
91 }
92
93 # Simplify calls to less, automatically redirects all output.
94 alias -g L='2>&1 | less'
95 # Simplify calls to colordiff, output is also piped through less.
96 alias -g D='2>&1 | colordiff L'
97 # Simplify calls to grep.
98 alias -g G='| grep'
99
100 # Improved ls which displays the files in columns (-C), visualises directories,
101 # links and other special files (-F) and pages everything through less (L).
102 #
103 # If available use GNU ls with colorized output. If it isn't available use
104 # normal ls which needs CLICOLOR_FORCE so it displays colors when used with a
105 # pager.
106 ls --color &> /dev/null
107 if [[ $? -eq 0 ]]; then
108     alias ls='ls --color'
109 else
110     alias ls='CLICOLOR_FORCE=1 ls -G'
111 fi
112 # Main ls function.
113 function ls() {
114     command ls -C -F $* L
115 }
116 # Helper function to list all files.
117 function la() {
118     ls -a $*
119 }
120 # Helper function to list all files in list format with access rights, etc.
121 function ll() {
122     la -l $*
123 }
124
125
126 # Load rc file for current OS.
127 source_config ~/.zsh os rc $(uname) nolocal
128 # Load rc file for current hostname (first part before a dot) or rc.local.
129 source_config ~/.zsh host rc ${$(hostname)//.*/}