mirror of
https://github.com/fish-shell/fish-shell.git
synced 2026-06-28 13:11:15 -03:00
Don't print greetings in interactive read in fake-interactive shell
If a user passes "-i" when running a script, they ought to expect weird behavior i.e. fish might run the user's interactive-only configuration which might print things to TTY etc. But at least for our part of the configuration, we can avoid depending on the user-settable interactive bit. __fish_config_interactive is already only called when we paint the first prompt, either for a prompt (which implies we're an interactive shell) or for builtin read (which does not imply anything about the interactivity of the shell). Only print greetings when not in interactive read. Notably, "status is-interactive-read" is not overridable by the user. This helps us get rid of more "status is-interactive" switches.
This commit is contained in:
@@ -29,14 +29,14 @@ function __fish_config_interactive -d "Initializations that should be performed
|
||||
# The default just prints a variable of the same name.
|
||||
#
|
||||
# NOTE: This status check is necessary to not print the greeting when `read`ing in scripts. See #7080.
|
||||
if status is-interactive
|
||||
if not status is-interactive-read
|
||||
and functions -q fish_greeting
|
||||
fish_greeting
|
||||
end
|
||||
|
||||
# Display SHELL_WELCOME if set. This is a standard environment variable (introduced by
|
||||
# systemd v257) intended for shells to display when they first initialize.
|
||||
if status is-interactive
|
||||
if not status is-interactive-read
|
||||
and set -q SHELL_WELCOME[1]
|
||||
string join -- ' ' $SHELL_WELCOME
|
||||
end
|
||||
|
||||
@@ -1,14 +1,16 @@
|
||||
#RUN: %fish %s
|
||||
#RUN: fish=%fish %fish %s
|
||||
#REQUIRES: command -v tmux
|
||||
#REQUIRES: test -z "$CI"
|
||||
|
||||
isolated-tmux-start -C '
|
||||
function fish_greeting
|
||||
set -l name (read)
|
||||
echo hello $name
|
||||
end
|
||||
printf >?$__fish_config_dir/functions/fish_greeting.fish %s \
|
||||
'function fish_greeting
|
||||
set -l name (read)
|
||||
echo hello $name
|
||||
end
|
||||
'
|
||||
|
||||
isolated-tmux-start
|
||||
|
||||
isolated-tmux send-keys name Enter 'echo foo' Enter
|
||||
tmux-sleep
|
||||
isolated-tmux capture-pane -p
|
||||
@@ -17,3 +19,12 @@ isolated-tmux capture-pane -p
|
||||
# CHECK: prompt 0> echo foo
|
||||
# CHECK: foo
|
||||
# CHECK: prompt 1>
|
||||
|
||||
isolated-tmux send-keys C-l 'SHELL_WELCOME=hello $fish -ic "read --prompt-str=R"' Enter
|
||||
tmux-sleep
|
||||
isolated-tmux send-keys C-c
|
||||
tmux-sleep
|
||||
isolated-tmux capture-pane -p
|
||||
# CHECK: prompt 1> SHELL_WELCOME=hello $fish -ic "read --prompt-str=R"
|
||||
# CHECK: R
|
||||
# CHECK: prompt 2>
|
||||
|
||||
@@ -41,9 +41,13 @@ function isolated-tmux-start --wraps fish
|
||||
|
||||
set -l fish (status fish-path)
|
||||
set -l size -x 80 -y 10
|
||||
set -l greeting_file
|
||||
if not test -f $greeting_file
|
||||
printf >$__fish_config_dir/functions/fish_greeting.fish %s \
|
||||
'function fish_greeting; end' 2>/dev/null
|
||||
end
|
||||
isolated-tmux new-session $size -d $fish -C '
|
||||
# This is similar to "tests/interactive.config".
|
||||
function fish_greeting; end
|
||||
function fish_prompt; printf "prompt $status_generation> "; end
|
||||
# No autosuggestion from older history.
|
||||
set fish_history ""
|
||||
|
||||
Reference in New Issue
Block a user