2015-12-16 01:15:30 -05:00
|
|
|
#
|
|
|
|
# Editor and input char assignment
|
|
|
|
#
|
|
|
|
|
|
|
|
|
|
|
|
# Return if requirements are not found.
|
2015-12-19 09:48:29 -05:00
|
|
|
if [[ ${TERM} == 'dumb' ]]; then
|
2015-12-16 01:15:30 -05:00
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Use human-friendly identifiers.
|
2018-04-18 18:24:48 -04:00
|
|
|
zmodload -F zsh/terminfo +b:echoti +p:terminfo
|
2015-12-16 01:15:30 -05:00
|
|
|
typeset -gA key_info
|
|
|
|
key_info=(
|
|
|
|
'Control' '\C-'
|
2015-12-29 06:00:09 -05:00
|
|
|
'ControlLeft' '\e[1;5D \e[5D \e\e[D \eOd \eOD'
|
|
|
|
'ControlRight' '\e[1;5C \e[5C \e\e[C \eOc \eOC'
|
2015-12-16 01:15:30 -05:00
|
|
|
'Escape' '\e'
|
|
|
|
'Meta' '\M-'
|
2018-04-13 16:23:53 -04:00
|
|
|
'Backspace' ${terminfo[kbs]}
|
|
|
|
'BackTab' ${terminfo[kcbt]}
|
|
|
|
'Left' ${terminfo[kcub1]}
|
|
|
|
'Down' ${terminfo[kcud1]}
|
|
|
|
'Right' ${terminfo[kcuf1]}
|
|
|
|
'Up' ${terminfo[kcuu1]}
|
|
|
|
'Delete' ${terminfo[kdch1]}
|
|
|
|
'End' ${terminfo[kend]}
|
|
|
|
'F1' ${terminfo[kf1]}
|
|
|
|
'F2' ${terminfo[kf2]}
|
|
|
|
'F3' ${terminfo[kf3]}
|
|
|
|
'F4' ${terminfo[kf4]}
|
|
|
|
'F5' ${terminfo[kf5]}
|
|
|
|
'F6' ${terminfo[kf6]}
|
|
|
|
'F7' ${terminfo[kf7]}
|
|
|
|
'F8' ${terminfo[kf8]}
|
|
|
|
'F9' ${terminfo[kf9]}
|
|
|
|
'F10' ${terminfo[kf10]}
|
|
|
|
'F11' ${terminfo[kf11]}
|
|
|
|
'F12' ${terminfo[kf12]}
|
|
|
|
'Home' ${terminfo[khome]}
|
|
|
|
'Insert' ${terminfo[kich1]}
|
|
|
|
'PageDown' ${terminfo[knp]}
|
|
|
|
'PageUp' ${terminfo[kpp]}
|
2015-12-16 01:15:30 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
# Bind the keys
|
2016-01-09 05:27:55 -05:00
|
|
|
|
|
|
|
local key
|
2015-12-29 06:00:09 -05:00
|
|
|
for key in "${(s: :)key_info[ControlLeft]}"; do
|
|
|
|
bindkey ${key} backward-word
|
|
|
|
done
|
|
|
|
for key in "${(s: :)key_info[ControlRight]}"; do
|
|
|
|
bindkey ${key} forward-word
|
|
|
|
done
|
|
|
|
|
2018-04-13 16:23:53 -04:00
|
|
|
[[ -n ${key_info[Home]} ]] && bindkey ${key_info[Home]} beginning-of-line
|
|
|
|
[[ -n ${key_info[End]} ]] && bindkey ${key_info[End]} end-of-line
|
2016-08-15 06:35:57 -04:00
|
|
|
|
2018-04-13 16:23:53 -04:00
|
|
|
[[ -n ${key_info[PageUp]} ]] && bindkey ${key_info[PageUp]} up-line-or-history
|
|
|
|
[[ -n ${key_info[PageDown]} ]] && bindkey ${key_info[PageDown]} down-line-or-history
|
2016-08-15 06:35:57 -04:00
|
|
|
|
2018-04-13 16:23:53 -04:00
|
|
|
[[ -n ${key_info[Insert]} ]] && bindkey ${key_info[Insert]} overwrite-mode
|
2015-12-16 01:15:30 -05:00
|
|
|
|
2018-04-13 16:23:53 -04:00
|
|
|
if [[ ${zdouble_dot_expand} == 'true' ]]; then
|
2016-05-20 23:25:01 -04:00
|
|
|
double-dot-expand() {
|
|
|
|
if [[ ${LBUFFER} == *.. ]]; then
|
|
|
|
LBUFFER+='/..'
|
|
|
|
else
|
|
|
|
LBUFFER+='.'
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
zle -N double-dot-expand
|
2018-04-13 16:23:53 -04:00
|
|
|
bindkey '.' double-dot-expand
|
2016-05-20 23:25:01 -04:00
|
|
|
fi
|
|
|
|
|
2018-04-13 16:23:53 -04:00
|
|
|
[[ -n ${key_info[Backspace]} ]] && bindkey ${key_info[Backspace]} backward-delete-char
|
|
|
|
[[ -n ${key_info[Delete]} ]] && bindkey ${key_info[Delete]} delete-char
|
2015-12-16 01:15:30 -05:00
|
|
|
|
2018-04-13 16:23:53 -04:00
|
|
|
[[ -n ${key_info[Left]} ]] && bindkey ${key_info[Left]} backward-char
|
|
|
|
[[ -n ${key_info[Right]} ]] && bindkey ${key_info[Right]} forward-char
|
2015-12-16 01:15:30 -05:00
|
|
|
|
|
|
|
# Expandpace.
|
|
|
|
bindkey ' ' magic-space
|
|
|
|
|
2016-06-22 10:28:46 -04:00
|
|
|
# Clear
|
2015-12-19 09:48:29 -05:00
|
|
|
bindkey "${key_info[Control]}L" clear-screen
|
2015-12-16 01:15:30 -05:00
|
|
|
|
|
|
|
# Bind Shift + Tab to go to the previous menu item.
|
2018-04-13 16:23:53 -04:00
|
|
|
[[ -n ${key_info[BackTab]} ]] && bindkey ${key_info[BackTab]} reverse-menu-complete
|
2015-12-29 06:00:09 -05:00
|
|
|
|
2018-04-13 16:15:54 -04:00
|
|
|
autoload -Uz is-at-least && if ! is-at-least 5.3; then
|
|
|
|
# Redisplay after completing, and avoid blank prompt after <Tab><Tab><Ctrl-C>
|
|
|
|
expand-or-complete-with-redisplay() {
|
|
|
|
print -Pn '...'
|
|
|
|
zle expand-or-complete
|
|
|
|
zle redisplay
|
|
|
|
}
|
|
|
|
zle -N expand-or-complete-with-redisplay
|
|
|
|
bindkey "${key_info[Control]}I" expand-or-complete-with-redisplay
|
|
|
|
fi
|
2016-09-28 19:03:06 -04:00
|
|
|
|
2015-12-29 06:00:09 -05:00
|
|
|
# Put into application mode and validate ${terminfo}
|
|
|
|
zle-line-init() {
|
2018-04-13 16:23:53 -04:00
|
|
|
(( ${+terminfo[smkx]} )) && echoti smkx
|
2015-12-29 06:00:09 -05:00
|
|
|
}
|
|
|
|
zle-line-finish() {
|
2018-04-13 16:23:53 -04:00
|
|
|
(( ${+terminfo[rmkx]} )) && echoti rmkx
|
2015-12-29 06:00:09 -05:00
|
|
|
}
|
|
|
|
zle -N zle-line-init
|
|
|
|
zle -N zle-line-finish
|