1
0
Fork 0
mirror of synced 2024-11-26 09:15:34 -05:00

[input] Only load terminfo feature of zsh/terminfo

and use `-F` to check if the feature was not already loaded before.

Use terminfo elements for Backspace and Delete. Sort by terminfo element
keys.

Also simplify code, removing unnecessary double quotes, and replacing
if-then-fi with one command by one-liners.
This commit is contained in:
Eric Nielsen 2018-04-13 15:23:53 -05:00
parent 26dce76d28
commit 78611457f2

View file

@ -9,7 +9,7 @@ if [[ ${TERM} == 'dumb' ]]; then
fi fi
# Use human-friendly identifiers. # Use human-friendly identifiers.
zmodload zsh/terminfo zmodload -F zsh/terminfo +p:terminfo
typeset -gA key_info typeset -gA key_info
key_info=( key_info=(
'Control' '\C-' 'Control' '\C-'
@ -17,30 +17,30 @@ key_info=(
'ControlRight' '\e[1;5C \e[5C \e\e[C \eOc \eOC' 'ControlRight' '\e[1;5C \e[5C \e\e[C \eOc \eOC'
'Escape' '\e' 'Escape' '\e'
'Meta' '\M-' 'Meta' '\M-'
'Backspace' "^?" 'Backspace' ${terminfo[kbs]}
'Delete' "^[[3~" 'BackTab' ${terminfo[kcbt]}
'F1' "${terminfo[kf1]}" 'Left' ${terminfo[kcub1]}
'F2' "${terminfo[kf2]}" 'Down' ${terminfo[kcud1]}
'F3' "${terminfo[kf3]}" 'Right' ${terminfo[kcuf1]}
'F4' "${terminfo[kf4]}" 'Up' ${terminfo[kcuu1]}
'F5' "${terminfo[kf5]}" 'Delete' ${terminfo[kdch1]}
'F6' "${terminfo[kf6]}" 'End' ${terminfo[kend]}
'F7' "${terminfo[kf7]}" 'F1' ${terminfo[kf1]}
'F8' "${terminfo[kf8]}" 'F2' ${terminfo[kf2]}
'F9' "${terminfo[kf9]}" 'F3' ${terminfo[kf3]}
'F10' "${terminfo[kf10]}" 'F4' ${terminfo[kf4]}
'F11' "${terminfo[kf11]}" 'F5' ${terminfo[kf5]}
'F12' "${terminfo[kf12]}" 'F6' ${terminfo[kf6]}
'Insert' "${terminfo[kich1]}" 'F7' ${terminfo[kf7]}
'Home' "${terminfo[khome]}" 'F8' ${terminfo[kf8]}
'PageUp' "${terminfo[kpp]}" 'F9' ${terminfo[kf9]}
'End' "${terminfo[kend]}" 'F10' ${terminfo[kf10]}
'PageDown' "${terminfo[knp]}" 'F11' ${terminfo[kf11]}
'Up' "${terminfo[kcuu1]}" 'F12' ${terminfo[kf12]}
'Left' "${terminfo[kcub1]}" 'Home' ${terminfo[khome]}
'Down' "${terminfo[kcud1]}" 'Insert' ${terminfo[kich1]}
'Right' "${terminfo[kcuf1]}" 'PageDown' ${terminfo[knp]}
'BackTab' "${terminfo[kcbt]}" 'PageUp' ${terminfo[kpp]}
) )
# Bind the keys # Bind the keys
@ -53,27 +53,15 @@ for key in "${(s: :)key_info[ControlRight]}"; do
bindkey ${key} forward-word bindkey ${key} forward-word
done done
if [[ -n "${key_info[Home]}" ]]; then [[ -n ${key_info[Home]} ]] && bindkey ${key_info[Home]} beginning-of-line
bindkey "${key_info[Home]}" beginning-of-line [[ -n ${key_info[End]} ]] && bindkey ${key_info[End]} end-of-line
fi
if [[ -n "${key_info[End]}" ]]; then [[ -n ${key_info[PageUp]} ]] && bindkey ${key_info[PageUp]} up-line-or-history
bindkey "${key_info[End]}" end-of-line [[ -n ${key_info[PageDown]} ]] && bindkey ${key_info[PageDown]} down-line-or-history
fi
if [[ -n "${key_info[PageUp]}" ]]; then [[ -n ${key_info[Insert]} ]] && bindkey ${key_info[Insert]} overwrite-mode
bindkey "${key_info[PageUp]}" up-line-or-history
fi
if [[ -n "${key_info[PageDown]}" ]]; then if [[ ${zdouble_dot_expand} == 'true' ]]; then
bindkey "${key_info[PageDown]}" down-line-or-history
fi
if [[ -n "${key_info[Insert]}" ]]; then
bindkey "${key_info[Insert]}" overwrite-mode
fi
if [[ ${zdouble_dot_expand} == "true" ]]; then
double-dot-expand() { double-dot-expand() {
if [[ ${LBUFFER} == *.. ]]; then if [[ ${LBUFFER} == *.. ]]; then
LBUFFER+='/..' LBUFFER+='/..'
@ -82,14 +70,14 @@ if [[ ${zdouble_dot_expand} == "true" ]]; then
fi fi
} }
zle -N double-dot-expand zle -N double-dot-expand
bindkey "." double-dot-expand bindkey '.' double-dot-expand
fi fi
bindkey "${key_info[Delete]}" delete-char [[ -n ${key_info[Backspace]} ]] && bindkey ${key_info[Backspace]} backward-delete-char
bindkey "${key_info[Backspace]}" backward-delete-char [[ -n ${key_info[Delete]} ]] && bindkey ${key_info[Delete]} delete-char
bindkey "${key_info[Left]}" backward-char [[ -n ${key_info[Left]} ]] && bindkey ${key_info[Left]} backward-char
bindkey "${key_info[Right]}" forward-char [[ -n ${key_info[Right]} ]] && bindkey ${key_info[Right]} forward-char
# Expandpace. # Expandpace.
bindkey ' ' magic-space bindkey ' ' magic-space
@ -98,9 +86,7 @@ bindkey ' ' magic-space
bindkey "${key_info[Control]}L" clear-screen bindkey "${key_info[Control]}L" clear-screen
# Bind Shift + Tab to go to the previous menu item. # Bind Shift + Tab to go to the previous menu item.
if [[ -n "${key_info[BackTab]}" ]]; then [[ -n ${key_info[BackTab]} ]] && bindkey ${key_info[BackTab]} reverse-menu-complete
bindkey "${key_info[BackTab]}" reverse-menu-complete
fi
autoload -Uz is-at-least && if ! is-at-least 5.3; then autoload -Uz is-at-least && if ! is-at-least 5.3; then
# Redisplay after completing, and avoid blank prompt after <Tab><Tab><Ctrl-C> # Redisplay after completing, and avoid blank prompt after <Tab><Tab><Ctrl-C>
@ -115,14 +101,10 @@ fi
# Put into application mode and validate ${terminfo} # Put into application mode and validate ${terminfo}
zle-line-init() { zle-line-init() {
if (( ${+terminfo[smkx]} )); then (( ${+terminfo[smkx]} )) && echoti smkx
echoti smkx
fi
} }
zle-line-finish() { zle-line-finish() {
if (( ${+terminfo[rmkx]} )); then (( ${+terminfo[rmkx]} )) && echoti rmkx
echoti rmkx
fi
} }
zle -N zle-line-init zle -N zle-line-init
zle -N zle-line-finish zle -N zle-line-finish