fix: standardize shell escape character to octal

URxvt requires octal for keysym while others do not and querying a
single one is easier.
This commit is contained in:
Ben Grande 2025-01-22 17:42:01 +01:00
parent 7928a352be
commit a7d2876bb4
No known key found for this signature in database
GPG Key ID: 00C64E14F51F9E56
7 changed files with 81 additions and 81 deletions

View File

@ -62,7 +62,7 @@ _reset_line() {
unset cur_y
## Print line ending char with reversed video and end with newline.
if test "${color_prompt-}" = "yes"; then
printf '%b' "\033[41m\033[0m\033[7m%\033[m\n\r"
printf '%b' "\033[41m\033[0m\033[7m%\033[0m\n\r"
else
printf '%b' "%\n\r"
fi
@ -100,7 +100,7 @@ fi
case "${TERM-}" in
screen*|xterm*|rxvt*)
## Set window title
PS1="\[\e]0;${debian_chroot:+(${debian_chroot})}\u@\h: \w\a\]${PS1}"
PS1="\[\033]0;${debian_chroot:+(${debian_chroot})}\u@\h: \w\a\]${PS1}"
;;
*) ;;
esac
@ -112,7 +112,7 @@ case "${TERM-}" in
*)
## Reset cursor to steady block after command input and before execution.
# shellcheck disable=SC2034
PS0="\e[2 q\2"
PS0="\033[2 q\2"
;;
esac
if ! shopt -oq posix; then

View File

@ -20,13 +20,13 @@ set editing-mode emacs
set show-mode-in-prompt on
$if term=linux
set emacs-mode-string "\1\e[?0c\2"
set vi-ins-mode-string "\1\e[?0c\2"
set vi-cmd-mode-string "\1\e[?8c\2"
set emacs-mode-string "\1\033[?0c\2"
set vi-ins-mode-string "\1\033[?0c\2"
set vi-cmd-mode-string "\1\033[?8c\2"
$else
set emacs-mode-string "\1\e[5 q\2"
set vi-ins-mode-string "\1\e[5 q\2"
set vi-cmd-mode-string "\1\e[2 q\2"
set emacs-mode-string "\1\033[5 q\2"
set vi-ins-mode-string "\1\033[5 q\2"
set vi-cmd-mode-string "\1\033[2 q\2"
$endif
$if term=''
@ -59,8 +59,8 @@ $if mode=emacs
set keymap emacs-ctlx
v: vi-editing-mode
Control-v: "\C-xv\e"
Esc: "\C-xv\e"
Control-v: "\C-xv\033"
Esc: "\C-xv\033"
set keymap emacs
$else
@ -117,46 +117,46 @@ $endif
## Home
"\e[1~": beginning-of-line
"\e[H": beginning-of-line
"\eOH": beginning-of-line
"\033[1~": beginning-of-line
"\033[H": beginning-of-line
"\033OH": beginning-of-line
## End
"\e[4~": end-of-line
"\e[F": end-of-line
"\eOF": end-of-line
"\033[4~": end-of-line
"\033[F": end-of-line
"\033OF": end-of-line
## Delete
"\e[3~": delete-char
"\e[P": delete-char
"\eOP": delete-char
"\033[3~": delete-char
"\033[P": delete-char
"\033OP": delete-char
## Insert
"\e[2~": quoted-insert
"\e[L": quoted-insert
"\033[2~": quoted-insert
"\033[L": quoted-insert
## PgUp
"\e[5~": beginning-of-history
"\e[I": beginning-of-history
"\033[5~": beginning-of-history
"\033[I": beginning-of-history
## PgDown
"\e[6~": end-of-history
"\e[G": end-of-history
"\033[6~": end-of-history
"\033[G": end-of-history
## Ctrl+RighArrow
"\e[1;5C": forward-word
"\e[5C": forward-word
"\e\e[C": forward-word
"\033[1;5C": forward-word
"\033[5C": forward-word
"\033\033[C": forward-word
## Ctrl+LeftArrow
"\e[1;5D": backward-word
"\e[5D": backward-word
"\e\e[D": backward-word
"\033[1;5D": backward-word
"\033[5D": backward-word
"\033\033[D": backward-word
## Terminal
$if term=rxvt
"\e[7~": beginning-of-line
"\e[8~": end-of-line
"\eOc": forward-word
"\eOd": backward-word
"\033[7~": beginning-of-line
"\033[8~": end-of-line
"\033Oc": forward-word
"\033Od": backward-word
$endif

View File

@ -18,4 +18,4 @@ i toggle-option i
^F right
^N down
^P up
\ef word-right
\033f word-right

View File

@ -241,14 +241,14 @@ _git_prompt_info(){
test "${ref-}" || return
# shellcheck disable=2039,3003
case "${TERM-}" in
*-256color|xterm-kitty) branchcolor=$'\e[38;5;31m' ;;
*-88color|rxvt-unicode) branchcolor=$'\e[38;5;22m' ;;
*) branchcolor=$'\e[00;94m' ;;
*-256color|xterm-kitty) branchcolor=$'\033[38;5;31m' ;;
*-88color|rxvt-unicode) branchcolor=$'\033[38;5;22m' ;;
*) branchcolor=$'\033[0;94m' ;;
esac
if test -n "${ZSH_VERSION-}"; then
# shellcheck disable=2016
if test "${color_prompt}" = "yes"; then
print -Pn '(%%{${branchcolor}%%}%20>...>${ref}%<<%%{\e[00m%%})'
print -Pn '(%%{${branchcolor}%%}%20>...>${ref}%<<%%{\033[0m%%})'
else
print -Pn '(%20>...>${ref}%<<)'
fi
@ -263,22 +263,22 @@ _git_prompt_info(){
}
# shellcheck disable=SC2034
reset_color="$(printf '%b' '\e[00m')"
reset_color="$(printf '%b' '\033[0m')"
# shellcheck disable=SC2034
## Use echotc Co? Only available by default for zsh, not bash.
case "${TERM-}" in
*-256color|xterm-kitty)
usercolor="$(printf '%b' "\e[38;5;184m")"
dircolor="$(printf '%b' "\e[38;5;27m")"
usercolor="$(printf '%b' "\033[38;5;184m")"
dircolor="$(printf '%b' "\033[38;5;27m")"
;;
*-88color|rxvt-unicode)
usercolor="$(printf '%b' "\e[38;5;56m")"
dircolor="$(printf '%b' "\e[38;5;23m")"
usercolor="$(printf '%b' "\033[38;5;56m")"
dircolor="$(printf '%b' "\033[38;5;23m")"
;;
*)
usercolor="$(printf '%b' "\e[00;93m")"
dircolor="$(printf '%b' "\e[01;34m")"
usercolor="$(printf '%b' "\033[0;93m")"
dircolor="$(printf '%b' "\033[1;34m")"
;;
esac
@ -290,7 +290,7 @@ esac
# shellcheck disable=SC2034
uid="$(id -u)"
if test "${uid}" = "0"; then
usercolor="$(printf '%b' "\e[00;97m")"
usercolor="$(printf '%b' "\033[0;97m")"
ps1_symbol="#"
fi
unset uid

View File

@ -77,7 +77,7 @@ if test "${color_prompt-}" = "yes"; then
PS1="\$(resize-terminal)%F{magenta}[%{$usercolor%}%n@%m%F{reset_color%}"
PS1="${PS1} %{$dircolor%}%50<...<%~%<<%F{reset_color%}\$(_git_prompt_info)"
PS1="${PS1}%F{magenta}]%F{reset_color}${newline-}${ps1_symbol} "
RPS1="%(?..(%{"$'\e[31m'"%}%?%{$reset_color%}%)%<<)"
RPS1="%(?..(%{"$'\033[31m'"%}%?%{$reset_color%}%)%<<)"
else
PS1="\$(resize-terminal)[%n@%M %~\$(_git_prompt_info)]${newline}"
PS1="${PS1}${ps1_symbol} "
@ -90,8 +90,8 @@ _set_title() {
*install*)
hash -r ;;
esac
print -Pn '\e]1;%l@%m${1+*}\a'
print -Pn '\e]2;%n@%m:%~'
print -Pn '\033]1;%l@%m${1+*}\a'
print -Pn '\033]2;%n@%m:%~'
if test -n "${1:-}"; then
print -Pnr ' (%24>..>$1%>>)' | tr '\0-\037' '?'
fi
@ -103,20 +103,20 @@ case "${TERM-}" in
precmd() {
_set_title "$@"
if [ "${STY:-}" -o "${TMUX:-}" ]; then
# print -Pn "\e]1;\a\e]1;@%m\a"
print -Pn '\ek@\e\\'
# print -Pn "\033]1;\a\033]1;@%m\a"
print -Pn '\033k@\033\\'
else
print -Pn '\ek@%m\e\\'
print -Pn '\033k@%m\033\\'
fi
}
preexec() {
_set_title "$@"
print -n "\ek"
print -n "\033k"
print -Pnr '%10>..>$1' | tr '\0-\037' '?'
if [ "${STY:-}" -o "${TMUX:-}" ]; then
print -Pn '@\e\\'
print -Pn '@\033\\'
else
print -Pn '@%m\e\\'
print -Pn '@%m\033\\'
fi
}
;;
@ -301,10 +301,10 @@ function clear-screen-and-scrollback() {
esac
test -n "${TTY-}" || return
echoti civis >"${TTY-}"
printf '%b' "\e[H\e[2J" >"${TTY-}"
printf '%b' "\033[H\033[2J" >"${TTY-}"
zle .reset-prompt
zle -R
printf '%b' "\e[3J" >"${TTY-}"
printf '%b' "\033[3J" >"${TTY-}"
echoti cnorm >"${TTY-}"
}
zle -N clear-screen-and-scrollback
@ -341,8 +341,8 @@ case "${TERM-}" in
*)
zle-keymap-select zle-line-init() {
case $KEYMAP in
vicmd) print -n -- "\e[2 q";;
viins|main) print -n -- "\e[5 q";;
vicmd) print -n -- "\033[2 q";;
viins|main) print -n -- "\033[5 q";;
esac
zle reset-prompt
@ -350,7 +350,7 @@ case "${TERM-}" in
}
zle-line-finish() {
print -n -- "\e[2 q"
print -n -- "\033[2 q"
}
zle -N zle-line-init
@ -420,56 +420,56 @@ bindkey -M menuselect "^M" accept-line
## https://invisible-island.net/xterm/xterm-function-keys.html
##
## Shit+Tab
bindkey-multi emacs viins menuselect -- "\E[Z" "${terminfo[kcbt]}" \
bindkey-multi emacs viins menuselect -- "\033[Z" "${terminfo[kcbt]}" \
-- reverse-menu-complete
## Backspace
bindkey-multi emacs viins vicmd menuselect -- "^H" "^?" "${terminfo[kbs]}" \
-- backward-delete-char
## Home
bindkey-multi emacs viins vicmd -- "\E[1~" "\E[7~" "\E[H" "\EOH" \
bindkey-multi emacs viins vicmd -- "\033[1~" "\033[7~" "\033[H" "\033OH" \
"${terminfo[khome]}" \
-- beginning-of-line
## Insert
bindkey-multi emacs viins vicmd -- "\E[2~" "\E[L" "${terminfo[kich1]}" \
bindkey-multi emacs viins vicmd -- "\033[2~" "\033[L" "${terminfo[kich1]}" \
-- overwrite-mode
## Delete
bindkey-multi emacs viins vicmd -- "\E[3~" "\E[P" "\EOP" \
bindkey-multi emacs viins vicmd -- "\033[3~" "\033[P" "\033OP" \
"${terminfo[kdch1]}" \
-- vi-delete-char
## End
bindkey-multi emacs viins vicmd -- "\E[4~" "\E[8~" "\E[F" "\EOF" \
bindkey-multi emacs viins vicmd -- "\033[4~" "\033[8~" "\033[F" "\033OF" \
"${terminfo[kend]}" \
-- end-of-line
## PgUp
bindkey-multi emacs viins -- "\E[5~" "\E[I" "${terminfo[kpp]}" \
bindkey-multi emacs viins -- "\033[5~" "\033[I" "${terminfo[kpp]}" \
-- beginning-of-buffer-or-history
## PgDown
bindkey-multi emacs viins -- "\E[6~" "\E[G" "${terminfo[knp]}" \
bindkey-multi emacs viins -- "\033[6~" "\033[G" "${terminfo[knp]}" \
-- end-of-buffer-or-history
## Up arrow
bindkey-multi emacs viins vicmd -- "\E[A" "\EOA" "${terminfo[kcuu1]}" \
bindkey-multi emacs viins vicmd -- "\033[A" "\033OA" "${terminfo[kcuu1]}" \
-- up-line-or-history
## Down arrow
bindkey-multi emacs viins vicmd -- "\E[B" "\EOB" "${terminfo[kcud1]}" \
bindkey-multi emacs viins vicmd -- "\033[B" "\033OB" "${terminfo[kcud1]}" \
-- down-line-or-history
## Right arrow
bindkey-multi emacs viins vicmd -- "\E[1C" "\E[C" "\EOC" \
bindkey-multi emacs viins vicmd -- "\033[1C" "\033[C" "\033OC" \
"${terminfo[kcuf1]}" \
-- forward-char
## Left arrow
bindkey-multi emacs viins vicmd -- "\E[D" "\EOD" "${terminfo[kcub1]}" \
bindkey-multi emacs viins vicmd -- "\033[D" "\033OD" "${terminfo[kcub1]}" \
-- backward-char
## Ctrl-Delete
bindkey-multi emacs viins vicmd -- "\E[3;5~" "\E[3\^" "${terminfo[kDC5]}" \
bindkey-multi emacs viins vicmd -- "\033[3;5~" "\033[3\^" "${terminfo[kDC5]}" \
-- kill-word
## Ctrl-RightArrow
bindkey-multi emacs viins vicmd -- "\E[1;5C" "\E0c" "${terminfo[kRIT5]}" \
bindkey-multi emacs viins vicmd -- "\033[1;5C" "\0330c" "${terminfo[kRIT5]}" \
-- forward-word
## Ctrl-LeftArrow
bindkey-multi emacs viins vicmd -- "\E[1;5D" "\E0d" "${terminfo[kLFT5]}" \
bindkey-multi emacs viins vicmd -- "\033[1;5D" "\0330d" "${terminfo[kLFT5]}" \
-- backward-word
## F11
bindkey-multi emacs viins -- "\E[23~" "${terminfo[kf11]}" -- new-screen
bindkey-multi emacs viins -- "\033[23~" "${terminfo[kf11]}" -- new-screen
autoload -Uz edit-command-line
zle -N edit-command-line
@ -477,7 +477,7 @@ bindkey -M emacs "^[e" edit-command-line
bindkey -M emacs "^X^E" edit-command-line
bindkey -M vicmd "^E" edit-command-line
bindkey -M emacs "\ea" change-first-word
bindkey -M emacs "\033a" change-first-word
bindkey -M emacs "^XD" describe-key-briefly
for binding in ${(f)$(bindkey -M emacs|grep -e '^"\^X')}; do

View File

@ -67,7 +67,7 @@ fi
## Non-POSIX compliant and fast.
stty -echo
printf '\e7\e[r\033[99999;99999H\e[6n\e8' >/dev/tty
printf '\0337\033[r\033[99999;99999H\033[6n\0338' >/dev/tty
# shellcheck disable=3045,SC2034
IFS='[;R' read -r -t 1 -s -d R _ rows cols _ </dev/tty || {
printf '%s\n' "${msg_unsupported}" >&2

View File

@ -53,7 +53,7 @@ set-option -g status-right-length '40'
set-option -g status-right-style 'fg=brightcyan,bg=black'
## Terminal capabilities and update environment
set-option -g terminal-overrides '*256color:Tc,xterm*:XT:Cc=\E]12;%p1%s\007:Cr=\E]112\007:Cs=\E[%p1%d q,rxvt-unicode*:XT:sitm@:ritm@'
set-option -g terminal-overrides '*256color:Tc,xterm*:XT:Cc=\033]12;%p1%s\007:Cr=\033]112\007:Cs=\033[%p1%d q,rxvt-unicode*:XT:sitm@:ritm@'
set-option -g update-environment "DISPLAY SSH_ASKPASS SSH_AUTH_SOCK SSH_AGENT_PID SSH_CONNECTION WINDOWID XAUTHORITY XDG_CURRENT_DESKTOP XDG_SESSION_DESKTOP"
set-environment -gu DBUS_SESSION_BUS_ADDRESS