home: zsh: refactor 'terminfo' handling

This is more readable.

Largely inspired by oh-my-zsh.
This commit is contained in:
Bruno BELANYI 2023-03-15 17:23:04 +00:00
parent bc5fa3f679
commit 2431f8f207

View file

@ -1,14 +1,5 @@
# shellcheck disable=2154
# The expression: (( ${+terminfo} )) should never fail, but does if we
# don't have a tty, perhaps due to a bug in the zsh/terminfo module.
if [[ "$TERM" != emacs ]] && (( ${+terminfo} )) 2>/dev/null; then
# Fix delete key not working
((${+terminfo[kdch1]})) && bindkey -- "${terminfo[kdch1]}" delete-char
# Enable Shift-Tab to go backwards in completion list
((${+terminfo[kcbt]})) && bindkey -- "${terminfo[kcbt]}" reverse-menu-complete
fi
# Fix Ctrl+u killing from the cursor instead of the whole line
bindkey '^u' backward-kill-line
@ -18,5 +9,34 @@ zle -N edit-command-line
bindkey '^xe' edit-command-line
bindkey '^x^e' edit-command-line
# The expression: (( ${+terminfo} )) should never fail, but does if we
# don't have a tty, perhaps due to a bug in the zsh/terminfo module.
if ! { [ "$TERM" != emacs ] && (( ${+terminfo} )) 2>/dev/null; }; then
return
fi
# Fix delete key not working
if [ -n "${terminfo[kdch1]}" ]; then
bindkey -M emacs "${terminfo[kdch1]}" delete-char
bindkey -M viins "${terminfo[kdch1]}" delete-char
bindkey -M vicmd "${terminfo[kdch1]}" delete-char
else
bindkey -M emacs "^[[3~" delete-char
bindkey -M viins "^[[3~" delete-char
bindkey -M vicmd "^[[3~" delete-char
bindkey -M emacs "^[3;5~" delete-char
bindkey -M viins "^[3;5~" delete-char
bindkey -M vicmd "^[3;5~" delete-char
fi
# Enable Shift-Tab to go backwards in completion list
bindkey '^[[Z' reverse-menu-complete
if [ -n "${terminfo[kcbt]}" ]; then
bindkey -M emacs "${terminfo[kcbt]}" reverse-menu-complete
bindkey -M viins "${terminfo[kcbt]}" reverse-menu-complete
bindkey -M vicmd "${terminfo[kcbt]}" reverse-menu-complete
else
bindkey -M emacs '^[[Z' reverse-menu-complete
bindkey -M viins '^[[Z' reverse-menu-complete
bindkey -M vicmd '^[[Z' reverse-menu-complete
fi