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