From 99ddcbf7dced004da7790de4ab6a4df773c77239 Mon Sep 17 00:00:00 2001 From: Koichi Murase Date: Wed, 29 Oct 2025 11:46:04 +0900 Subject: [PATCH] fix(bash): use a different form of intermediate sequences --- crates/atuin/src/shell/atuin.bash | 37 ++++++++++++++++--------------- 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/crates/atuin/src/shell/atuin.bash b/crates/atuin/src/shell/atuin.bash index 26d63d85..aa46e917 100644 --- a/crates/atuin/src/shell/atuin.bash +++ b/crates/atuin/src/shell/atuin.bash @@ -377,16 +377,16 @@ __atuin_widget_run() { # of IKEYSEQ2 to no-op by running `bind '"IKEYSEQ2": ""'`. # # For the choice of the intermediate key sequences, we want to choose key -# sequences that are unlikely to conflict with others. For this, we consider -# the key sequences of the form \e[0;A. This is a variant of the key -# sequences for the [up] key. A single [up] keypress is usually transmitted as -# \e[A in the input stream, but it switches to the form \e[;A in the -# presence of modifier keys (such as Control or Shift), where represents -# the 1 + (modifier flags) and represents the number of [up] keypresses. -# The number is fixed to be 1 in the input stream, so we may use = 0 -# (which is unlikely be used) as our special key sequences. +# sequences that are unlikely to conflict with others. In addition, we want to +# avoid a key sequence containing \e because keymap "vi-insert" stops +# processing key sequences containing \e in older versions of Bash. We have +# used \e[0;A (a variant of the [up] key with modifier ) in Atuin 3.10.0 +# for intermediate key sequences, but this contains \e and caused a problem. +# Instead, we use \C-x\C-_A\a, which starts with \C-x\C-_ (an unlikely +# two-byte combination) and A (represents the initial letter of Atuin), +# followed by the payload and the terminator \a (BEL, \C-g). -__atuin_macro_chain='\e[0;0A' +__atuin_macro_chain='\C-x\C-_A0\a' for __atuin_keymap in emacs vi-insert vi-command; do bind -m "$__atuin_keymap" "\"$__atuin_macro_chain\": \"\"" done @@ -394,6 +394,7 @@ unset -v __atuin_keymap if ((BASH_VERSINFO[0] >= 5 || BASH_VERSINFO[0] == 4 && BASH_VERSINFO[1] >= 3)); then # In Bash >= 4.3 + __atuin_macro_accept_line=accept-line __atuin_bind_impl() { @@ -408,7 +409,7 @@ if ((BASH_VERSINFO[0] >= 5 || BASH_VERSINFO[0] == 4 && BASH_VERSINFO[1] >= 3)); local REPLY __atuin_widget_save "$keymap:$command" local widget=$REPLY - local ikeyseq1='\e[0;'$((1 + widget))'A' + local ikeyseq1='\C-x\C-_A'$((1 + widget))'\a' local ikeyseq2=$__atuin_macro_chain bind -m "$keymap" "\"$keyseq\": \"$ikeyseq1$ikeyseq2\"" @@ -489,21 +490,21 @@ else # `shell-expand-line'. # # Note: Concerning the key sequences to invoke bindable functions - # such as "\e[0;1A", another option is to use + # such as "\C-x\C-_A1\a", another option is to use # "\exbegginning-of-line\r", etc. to make it consistent with bash # >= 5.3. However, an older Bash configuration can still conflict - # on [M-x]. The conflict is more likely than \e[0;1A. + # on [M-x]. The conflict is more likely than \C-x\C-_A1\a. for __atuin_keymap in emacs vi-insert vi-command; do - bind -m "$__atuin_keymap" '"\e[0;1A": beginning-of-line' - bind -m "$__atuin_keymap" '"\e[0;2A": kill-line' - bind -m "$__atuin_keymap" '"\e[0;3A": shell-expand-line' - bind -m "$__atuin_keymap" '"\e[0;4A": accept-line' + bind -m "$__atuin_keymap" '"\C-x\C-_A1\a": beginning-of-line' + bind -m "$__atuin_keymap" '"\C-x\C-_A2\a": kill-line' + bind -m "$__atuin_keymap" '"\C-x\C-_A3\a": shell-expand-line' + bind -m "$__atuin_keymap" '"\C-x\C-_A4\a": accept-line' done unset -v __atuin_keymap # shellcheck disable=SC2016 - __atuin_macro_accept_line='"\e[0;1A\e[0;2A$READLINE_LINE\e[0;3A\e[0;4A"' + __atuin_macro_accept_line='"\C-x\C-_A1\a\C-x\C-_A2\a$READLINE_LINE\C-x\C-_A3\a\C-x\C-_A4\a"' # shellcheck disable=SC2016 - __atuin_macro_insert_line='"\e[0;1A\e[0;2A$READLINE_LINE\e[0;3A"' + __atuin_macro_insert_line='"\C-x\C-_A1\a\C-x\C-_A2\a$READLINE_LINE\C-x\C-_A3\a"' fi __atuin_bash42_dispatch_selector=