mirror of
https://github.com/fish-shell/fish-shell.git
synced 2026-06-08 02:31:18 -03:00
Fix regression causing cursor shape commands to leak into noninteractive shell
As reported in https://matrix.to/#/!YLTeaulxSDauOOxBoR:matrix.org/$CLuoHTdvcRj_8-HBBq0p-lmGWeix5khEtKEDxN2Ulfo Running fish -C ' fzf_key_bindings echo fish_vi_key_bindings >>~/.config/fish/config.fish fzf-history-widget ' and pressing "enter" will add escape sequences like "[2 q" (cursor shape) to fish's command line. This is because fzf-history-widget binds "enter" to a filter that happens to be a fish script: set -lx FZF_DEFAULT_OPTS \ ... \ "--bind='enter:become:string replace -a -- \n\t \n {2..} | string collect'" \ '--with-shell='(status fish-path)\\ -c) The above ~/.config/fish/config.fish (redundantly) runs "fish_vi_key_bindings" even in *noninteractive* shells, then "fish_vi_cursor" will print cursor sequences in its "fish_exit" handler. The sequence is not printed to the terminal but to fzf which doesn't parse CSI commands. This is a regression introduced bya5dfa84f73(fish_vi_cursor: skip if stdin is not a tty, 2023-11-14). That commit wanted "fish -c read" to be able to use Vi cursor. This is a noninteractive shell, but inside "read" we are "effectively interactive". However "status is-interactive" does not tell us that. Let's use a more contained fix to make sure that we print escape sequences only if either fish is interactive, or if we are evaluating an interactive read. In general, "fish -c read" is prone to configuration errors, since we recommend gating configuration (for bind etc) on "status is-interactive" which will not run here. (cherry picked from commit495083249b)
This commit is contained in:
@@ -18,6 +18,7 @@ set -l __fish_status_all_commands \
|
||||
is-full-job-control \
|
||||
is-interactive \
|
||||
is-interactive-job-control \
|
||||
is-interactive-read \
|
||||
is-login \
|
||||
is-no-job-control \
|
||||
job-control \
|
||||
@@ -32,6 +33,7 @@ complete -c status -s h -l help -d "Display help and exit"
|
||||
# The "is-something" subcommands.
|
||||
complete -f -c status -n "not __fish_seen_subcommand_from $__fish_status_all_commands" -a is-login -d "Test if this is a login shell"
|
||||
complete -f -c status -n "not __fish_seen_subcommand_from $__fish_status_all_commands" -a is-interactive -d "Test if this is an interactive shell"
|
||||
complete -f -c status -n "not __fish_seen_subcommand_from $__fish_status_all_commands" -a is-interactive-read -d "Test if inside an interactive read builtin"
|
||||
complete -f -c status -n "not __fish_seen_subcommand_from $__fish_status_all_commands" -a is-command-substitution -d "Test if a command substitution is currently evaluated"
|
||||
complete -f -c status -n "not __fish_seen_subcommand_from $__fish_status_all_commands" -a is-block -d "Test if a code block is currently evaluated"
|
||||
complete -f -c status -n "not __fish_seen_subcommand_from $__fish_status_all_commands" -a is-breakpoint -d "Test if a breakpoint is currently in effect"
|
||||
|
||||
@@ -1,13 +1,11 @@
|
||||
function fish_vi_cursor -d 'Set cursor shape for different vi modes'
|
||||
# if stdin is not a tty, there is effectively no bind mode.
|
||||
if not test -t 0
|
||||
return
|
||||
end
|
||||
|
||||
set -q fish_cursor_unknown
|
||||
or set -g fish_cursor_unknown block
|
||||
|
||||
function __fish_vi_cursor --argument-names varname
|
||||
if not status is-interactive; and not status is-interactive-read
|
||||
return
|
||||
end
|
||||
if not set -q $varname
|
||||
switch $varname
|
||||
case fish_cursor_insert
|
||||
|
||||
Reference in New Issue
Block a user