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