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