dot/shell-rc, etc.: Introduce an easily user-definable prompt section.
[profile] / dot / zshrc
index b4992b7..3466d6c 100644 (file)
--- a/dot/zshrc
+++ b/dot/zshrc
 __mdw_shell=zsh
 case ${INSIDE_EMACS+t},$TERM in t,dumb) unsetopt zle ;; esac
 
+###--------------------------------------------------------------------------
+### History settings.
+
+## Put this here so that `.shellrc-local' can override.
+
+HISTFILE=~/.zsh-history
+HISTSIZE=1000
+SAVEHIST=1000
+
+###--------------------------------------------------------------------------
+### Hook implementation.
+
+__mdw_precmd_hook= __mdw_preexec_hook=
+
+__mdw_run_precmd_hook () { __mdw_runhook __mdw_precmd_hook; }
+__mdw_run_preexec_hook () { __mdw_runhook __mdw_preexec_hook "$2"; }
+
+precmd_functions+=(__mdw_run_precmd_hook)
+preexec_functions+=(__mdw_run_preexec_hook)
+
+###--------------------------------------------------------------------------
+### Common shell configuration.
+
 . "$HOME/.shell-rc"
 
+## Fixup: `zsh' has sane quoting rules.
+__mdw_runhook () {
+  local hk=$1 saverc=$? t i; shift
+
+  eval t=\${$hk+t}
+  case $t in t) ;; *) echo >&2 "unknown hook \`$hk'"; return 2; esac
+
+  eval t=\$$hk
+  for i in ${=t}; do __mdw_setrc $saverc; "$i" "$@"; done
+}
+
 ###--------------------------------------------------------------------------
 ### Prompt hacking.
 
 __mdw_set_prompt_hacks () {
   case $TERM in
-    linux*|screen*|xterm*|vt100*|eterm*)
+    linux*|screen*|xterm*|putty*|vt100*|eterm*)
       bold=%B unbold=%b
-      gitcolour=%F{cyan} rccolour=%F{red} uncolour=%f
+      gitcolour=%F{cyan} extracolour=%F{yellow} rccolour=%F{red} uncolour=%f
       ;;
   esac
-  host=%m dir=" %(6~!%-1~/.../%5~!%~)"
+  host=%m dir=" %(6~!%-1~/.../%4~!%~)"
+  more=%F{green}%_%f
 }
 
 if [ -t 0 ]; then
   __mdw_source_if_exists /usr/lib/git-core/git-sh-prompt
   __mdw_set_prompt_pieces
-  precmd_functions+=(__mdw_precmd)
-  preexec_functions+=(__mdw_preexec)
 fi
 
 ###--------------------------------------------------------------------------
 ### Line editing.
 
-autoload -U select-word-style
-select-word-style bash
+case $TERM in dumb) unsetopt zle ;; esac
+
 bindkey -e
 
+for w in \
+  forward-word backward-word kill-word backward-kill-word \
+  transpose-words capitalize-word up-case-word down-case-word \
+  delete-whole-word select-word
+do
+  autoload -U $w-match
+  zle -N $w-bash $w-match
+  zle -N $w-shell $w-match
+  zstyle ':zle:*-bash' word-style standard
+  zstyle ':zle:*-bash' skip-whitespace-first true
+  zstyle ':zle:*-bash' word-chars ""
+  zstyle ':zle:*-shell' word-style shell
+  zstyle ':zle:*-shell' skip-whitespace-first false
+  zstyle ':completion:*' rehash true
+done
+
+bindkey "\eb" backward-word-bash
+bindkey "\e^b" backward-word-shell
+bindkey "\ef" forward-word-bash
+bindkey "\e^f" forward-word-shell
+bindkey "\e^?" backward-kill-word-bash
+bindkey "^w" backward-kill-word-shell
+bindkey "\ed" kill-word-bash
+bindkey "\e^d" kill-word-shell
+bindkey "\et" transpose-words-bash
+bindkey "\e^t" transpose-words-shell
+bindkey "\eu" up-case-word-bash
+bindkey "\e^u" up-case-word-shell
+bindkey "\el" down-case-word-bash
+bindkey "\e^l" down-case-word-shell
+bindkey "\ec" capitalize-word-bash
+bindkey "\e^c" capitalize-word-shell
+
+bindkey "\e[1~" beginning-of-line "\e[4~" end-of-line
+
+bindkey -s           "\eOQ" "/" "\eOR" "*" "\eOS" "-"
+bindkey -s "\eOw" "7" "\eOx" "8" "\eOy" "9"
+bindkey -s "\eOt" "4" "\eOu" "5" "\eOv" "6" "\eOk" "+"
+bindkey -s "\eOq" "1" "\eOr" "2" "\eOs" "3"
+bindkey -s "\eOp" "0"           "\eOn" "."; bindkey "\eOM" accept-line
+
+bindkey -s           "\eOQ" "/" "\eOR" "*" "\eOS" "-"
+bindkey -s "\eOw" "7" "\eOx" "8" "\eOy" "9"
+bindkey -s "\eOt" "4" "\eOu" "5" "\eOv" "6" "\eOk" "+"
+bindkey -s "\eOq" "1" "\eOr" "2" "\eOs" "3"
+bindkey -s "\eOp" "0"           "\eOn" "."; bindkey "\eOM" accept-line
+
+bindkey "\ep" history-beginning-search-backward
+bindkey "\en" history-beginning-search-forward
+bindkey "\e," _history-complete-older
+
+for i in '!' '$' '@' '/' '~'; do
+  bindkey "\e$i" _bash_complete-word
+  bindkey "^X$i" _bash_list-choices
+done
+
+setopt interactive_comments
+bindkey "\e#" pound-insert
+
+__mdw_delete_horizontal_space () {
+  LBUFFER=${LBUFFER%%[[:space:]]##}
+  RBUFFER=${RBUFFER##[[:space:]]##}
+}
+zle -N delete-horizontal-space __mdw_delete_horizontal_space
+bindkey "\e\\" delete-horizontal-space
+
+__mdw_just_one_space () {
+  LBUFFER="${LBUFFER%%[[:space:]]##} "
+  RBUFFER=${RBUFFER##[[:space:]]##}
+}
+zle -N just-one-space __mdw_just_one_space
+bindkey "\e " just-one-space
+
 ###--------------------------------------------------------------------------
 ### Completion.
 
-## Initialize the fancy completion machinery.
-autoload -Uz compinit
-compinit
-
 ## Contexts: :completion:FUNCTION:COMPLETER:COMMAND:ARGUMENT:TAG
 zstyle ':completion:*' completer _expand _complete _ignored _approximate
 zstyle ':completion:*' insert-unambiguous false
@@ -52,6 +154,10 @@ zstyle ':completion:*' original true
 zstyle ':completion:*' verbose false
 zstyle ':completion:*:*:git*:*' verbose true
 
+## Initialize the fancy completion machinery.
+autoload -Uz compinit
+compinit
+
 _r () { words[1]=sudo; _normal; }
 compdef _r rootly
 compdef _ssh @
@@ -59,33 +165,35 @@ compdef _ssh @
 ###--------------------------------------------------------------------------
 ### Other shell tweaking.
 
-HISTFILE=~/.zsh-history
-HISTSIZE=1000
-SAVEHIST=1000
-
-setopt appendhistory
 unsetopt auto_cd
 unsetopt auto_menu
+setopt bang_hist
 unsetopt bash_auto_list
 unsetopt beep
+setopt c_bases octal_zeroes
 setopt extendedglob
-setopt ksh_glob
+unsetopt flow_control
+unsetopt global_export
+setopt glob_star_short
+setopt hist_ignore_all_dups
+setopt hist_ignore_space
+unsetopt ksh_glob
 setopt list_ambiguous
 setopt list_packed
+setopt multios
 unsetopt nomatch
 unsetopt menu_complete
 setopt notify
+setopt rc_expand_param
+setopt rc_quotes
+setopt share_history
 
-zshaddhistory () {
-  case "$1" in
-    " "*) return 2 ;;
-    *) return 0 ;;
-  esac
-}
+hash -d t=$TMPDIR
 
 ###--------------------------------------------------------------------------
 ### Finishing touches.
 
+## Local tweaks.
 __mdw_source_if_exists "$HOME/.zshrc-local"
 
 ###----- That's all, folks --------------------------------------------------