chiark / gitweb /
dot/zshrc: Make M-p and M-n work properly.
[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 . "$HOME/.shell-rc"
9
10 ###--------------------------------------------------------------------------
11 ### Prompt hacking.
12
13 __mdw_set_prompt_hacks () {
14   case $TERM in
15     linux*|screen*|xterm*|vt100*|eterm*)
16       bold=%B unbold=%b
17       gitcolour=%F{cyan} rccolour=%F{red} uncolour=%f
18       ;;
19   esac
20   host=%m dir=" %(6~!%-1~/.../%5~!%~)"
21 }
22
23 if [ -t 0 ]; then
24   __mdw_source_if_exists /usr/lib/git-core/git-sh-prompt
25   __mdw_set_prompt_pieces
26   precmd_functions+=(__mdw_precmd)
27   preexec_functions+=(__mdw_preexec)
28 fi
29
30 ###--------------------------------------------------------------------------
31 ### Line editing.
32
33 bindkey -e
34
35 for w in \
36   forward-word backward-word kill-word backward-kill-word \
37   transpose-words capitalize-word up-case-word down-case-word \
38   delete-whole-word select-word
39 do
40   autoload -U $w-match
41   zle -N $w-bash $w-match
42   zle -N $w-shell $w-match
43   zstyle ':zle:*-bash' word-style standard
44   zstyle ':zle:*-bash' skip-whitespace-first true
45   zstyle ':zle:*-bash' word-chars ""
46   zstyle ':zle:*-shell' word-style shell
47   zstyle ':zle:*-shell' skip-whitespace-first false
48 done
49
50 bindkey "\eb" backward-word-bash
51 bindkey "\e^b" backward-word-shell
52 bindkey "\ef" forward-word-bash
53 bindkey "\e^f" forward-word-shell
54 bindkey "\e^?" backward-kill-word-bash
55 bindkey "^w" backward-kill-word-shell
56 bindkey "\ed" kill-word-bash
57 bindkey "\e^d" kill-word-shell
58 bindkey "\et" transpose-words-bash
59 bindkey "\e^t" transpose-words-shell
60 bindkey "\eu" up-case-word-bash
61 bindkey "\e^u" up-case-word-shell
62 bindkey "\el" up-case-word-bash
63 bindkey "\e^l" up-case-word-shell
64 bindkey "\ec" capitalize-word-bash
65 bindkey "\e^c" capitalize-word-shell
66
67 bindkey "\ep" history-beginning-search-backward
68 bindkey "\en" history-beginning-search-forward
69
70 __mdw_delete_horizontal_space () {
71   LBUFFER=${LBUFFER%%[[:space:]]##}
72   RBUFFER=${RBUFFER##[[:space:]]##}
73 }
74 zle -N delete-horizontal-space __mdw_delete_horizontal_space
75 bindkey "\e\\" delete-horizontal-space
76
77 __mdw_just_one_space () {
78   LBUFFER="${LBUFFER%%[[:space:]]##} "
79   RBUFFER=${RBUFFER##[[:space:]]##}
80 }
81 zle -N just-one-space __mdw_just_one_space
82 bindkey "\e " just-one-space
83
84
85 ###--------------------------------------------------------------------------
86 ### Completion.
87
88 ## Initialize the fancy completion machinery.
89 autoload -Uz compinit
90 compinit
91
92 ## Contexts: :completion:FUNCTION:COMPLETER:COMMAND:ARGUMENT:TAG
93 zstyle ':completion:*' completer _expand _complete _ignored _approximate
94 zstyle ':completion:*' insert-unambiguous false
95 zstyle ':completion:*' list-colors ${(s.:.)LS_COLORS}
96 zstyle ':completion:*' list-prompt %SAt %p: Hit TAB for more, or the character to insert%s
97 zstyle ':completion:*' matcher-list '' '+m:{[:lower:]}={[:upper:]} r:|[._-]=** r:|=**' '+l:|=* r:|=*'
98 zstyle ':completion:*' max-errors 0 numeric
99 zstyle ':completion:*' original true
100 zstyle ':completion:*' verbose false
101 zstyle ':completion:*:*:git*:*' verbose true
102
103 _r () { words[1]=sudo; _normal; }
104 compdef _r rootly
105 compdef _ssh @
106
107 ###--------------------------------------------------------------------------
108 ### Other shell tweaking.
109
110 HISTFILE=~/.zsh-history
111 HISTSIZE=1000
112 SAVEHIST=1000
113
114 setopt appendhistory
115 unsetopt auto_cd
116 unsetopt auto_menu
117 unsetopt bash_auto_list
118 unsetopt beep
119 setopt extendedglob
120 setopt ksh_glob
121 setopt list_ambiguous
122 setopt list_packed
123 unsetopt nomatch
124 unsetopt menu_complete
125 setopt notify
126
127 zshaddhistory () {
128   case "$1" in
129     " "*) return 2 ;;
130     *) return 0 ;;
131   esac
132 }
133
134 ###--------------------------------------------------------------------------
135 ### Finishing touches.
136
137 __mdw_source_if_exists "$HOME/.zshrc-local"
138
139 ###----- That's all, folks --------------------------------------------------