dot/zshrc: Enable option to substitute `BAR=...:~FOO:...:=BAZ:...'.
[profile] / dot / zshrc
... / ...
CommitLineData
1### -*-sh-*-
2###
3### Zsh session things.
4
5__mdw_shell=zsh
6
7###--------------------------------------------------------------------------
8### History settings.
9
10## Put this here so that `.shellrc-local' can override.
11
12HISTFILE=~/.zsh-history
13HISTSIZE=1000
14SAVEHIST=1000
15
16###--------------------------------------------------------------------------
17### Hook implementation.
18
19__mdw_precmd_hook= __mdw_preexec_hook=
20
21__mdw_run_precmd_hook () { __mdw_runhook __mdw_precmd_hook; }
22__mdw_run_preexec_hook () { __mdw_runhook __mdw_preexec_hook "$2"; }
23
24precmd_functions+=(__mdw_run_precmd_hook)
25preexec_functions+=(__mdw_run_preexec_hook)
26
27###--------------------------------------------------------------------------
28### Common shell configuration.
29
30. "$HOME/.shell-rc"
31
32## Fixup: `zsh' has sane quoting rules.
33__mdw_runhook () {
34 local hk=$1 saverc=$? t i; shift
35
36 eval t=\${$hk+t}
37 case $t in t) ;; *) echo >&2 "unknown hook \`$hk'"; return 2; esac
38
39 eval t=\$$hk
40 for i in ${=t}; do __mdw_setrc $saverc; "$i" "$@"; done
41}
42
43###--------------------------------------------------------------------------
44### Prompt hacking.
45
46__mdw_set_prompt_hacks () {
47 case $TERM in
48 linux*|screen*|xterm*|putty*|vt100*|eterm*)
49 bold=%B unbold=%b
50 gitcolour=%F{cyan} extracolour=%F{yellow} rccolour=%F{red} uncolour=%f
51 ;;
52 esac
53 host=%m dir=" %(6~!%-1~/.../%4~!%~)"
54 more=%F{green}%_%f
55}
56
57if [ -t 0 ]; then
58 __mdw_source_if_exists /usr/lib/git-core/git-sh-prompt
59 __mdw_set_prompt_pieces
60fi
61
62###--------------------------------------------------------------------------
63### Line editing.
64
65case ${INSIDE_EMACS+t},$TERM in t,dumb) unsetopt zle ;; esac
66case $TERM in dumb) unset zle_bracketed_paste ;; esac
67
68bindkey -e
69
70for w in \
71 forward-word backward-word kill-word backward-kill-word \
72 transpose-words capitalize-word up-case-word down-case-word \
73 delete-whole-word select-word
74do
75 autoload -U $w-match
76 zle -N $w-bash $w-match
77 zle -N $w-shell $w-match
78 zstyle ':zle:*-bash' word-style standard
79 zstyle ':zle:*-bash' skip-whitespace-first true
80 zstyle ':zle:*-bash' word-chars ""
81 zstyle ':zle:*-shell' word-style shell
82 zstyle ':zle:*-shell' skip-whitespace-first false
83 zstyle ':completion:*' rehash true
84done
85
86bindkey "\eb" backward-word-bash
87bindkey "\e^b" backward-word-shell
88bindkey "\ef" forward-word-bash
89bindkey "\e^f" forward-word-shell
90bindkey "\e^?" backward-kill-word-bash
91bindkey "^w" backward-kill-word-shell
92bindkey "\ed" kill-word-bash
93bindkey "\e^d" kill-word-shell
94bindkey "\et" transpose-words-bash
95bindkey "\e^t" transpose-words-shell
96bindkey "\eu" up-case-word-bash
97bindkey "\e^u" up-case-word-shell
98bindkey "\el" down-case-word-bash
99bindkey "\e^l" down-case-word-shell
100bindkey "\ec" capitalize-word-bash
101bindkey "\e^c" capitalize-word-shell
102
103bindkey "\e[1~" beginning-of-line "\e[4~" end-of-line
104
105bindkey -s "\eOQ" "/" "\eOR" "*" "\eOS" "-"
106bindkey -s "\eOw" "7" "\eOx" "8" "\eOy" "9"
107bindkey -s "\eOt" "4" "\eOu" "5" "\eOv" "6" "\eOk" "+"
108bindkey -s "\eOq" "1" "\eOr" "2" "\eOs" "3"
109bindkey -s "\eOp" "0" "\eOn" "."; bindkey "\eOM" accept-line
110
111bindkey -s "\eOQ" "/" "\eOR" "*" "\eOS" "-"
112bindkey -s "\eOw" "7" "\eOx" "8" "\eOy" "9"
113bindkey -s "\eOt" "4" "\eOu" "5" "\eOv" "6" "\eOk" "+"
114bindkey -s "\eOq" "1" "\eOr" "2" "\eOs" "3"
115bindkey -s "\eOp" "0" "\eOn" "."; bindkey "\eOM" accept-line
116
117bindkey "\ep" history-beginning-search-backward
118bindkey "\en" history-beginning-search-forward
119bindkey "\e," _history-complete-older
120
121for i in '!' '$' '@' '/' '~'; do
122 bindkey "\e$i" _bash_complete-word
123 bindkey "^X$i" _bash_list-choices
124done
125
126setopt interactive_comments
127bindkey "\e#" pound-insert
128
129__mdw_delete_horizontal_space () {
130 LBUFFER=${LBUFFER%%[[:space:]]##}
131 RBUFFER=${RBUFFER##[[:space:]]##}
132}
133zle -N delete-horizontal-space __mdw_delete_horizontal_space
134bindkey "\e\\" delete-horizontal-space
135
136__mdw_just_one_space () {
137 LBUFFER="${LBUFFER%%[[:space:]]##} "
138 RBUFFER=${RBUFFER##[[:space:]]##}
139}
140zle -N just-one-space __mdw_just_one_space
141bindkey "\e " just-one-space
142
143###--------------------------------------------------------------------------
144### Completion.
145
146## Contexts: :completion:FUNCTION:COMPLETER:COMMAND:ARGUMENT:TAG
147zstyle ':completion:*' completer _expand _complete _ignored _approximate
148zstyle ':completion:*' insert-unambiguous false
149zstyle ':completion:*' list-colors ${(s.:.)LS_COLORS}
150zstyle ':completion:*' list-prompt %SAt %p: Hit TAB for more, or the character to insert%s
151zstyle ':completion:*' matcher-list '' '+m:{[:lower:]}={[:upper:]} r:|[._-]=** r:|=**' '+l:|=* r:|=*'
152zstyle ':completion:*' max-errors 0 numeric
153zstyle ':completion:*' original true
154zstyle ':completion:*' verbose false
155zstyle ':completion:*:*:git*:*' verbose true
156
157## Initialize the fancy completion machinery.
158autoload -Uz compinit
159compinit
160
161_r () { words[1]=sudo; _normal; }
162compdef _r rootly
163compdef _ssh @
164
165###--------------------------------------------------------------------------
166### Other shell tweaking.
167
168unsetopt auto_cd
169unsetopt auto_menu
170setopt bang_hist
171unsetopt bash_auto_list
172unsetopt beep
173setopt c_bases octal_zeroes
174setopt extendedglob
175unsetopt flow_control
176unsetopt global_export
177setopt glob_star_short
178setopt hist_ignore_all_dups
179setopt hist_ignore_space
180unsetopt ksh_glob
181setopt list_ambiguous
182setopt list_packed
183setopt multios
184setopt magic_equal_subst
185unsetopt nomatch
186unsetopt menu_complete
187setopt notify
188setopt rc_expand_param
189setopt rc_quotes
190setopt share_history
191
192hash -d t=$TMPDIR
193
194###--------------------------------------------------------------------------
195### Finishing touches.
196
197## Local tweaks.
198__mdw_source_if_exists "$HOME/.zshrc-local"
199
200###----- That's all, folks --------------------------------------------------