Files
fish-shell/tests/test_functions/isolated-tmux-start.fish
Johannes Altmanninger 3dc36f74bc 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.
2026-05-11 10:21:56 +08:00

78 lines
2.5 KiB
Fish

function isolated-tmux-start --wraps fish
set -l tmpdir (mktemp -d)
cd $tmpdir
echo 'set -g mode-keys emacs' >.tmux.conf
function isolated-tmux --inherit-variable tmpdir --wraps tmux
# tmux can't handle session sockets in paths that are too long, and macOS has a very long
# $TMPDIR, so use a relative path - except macOS doesn't have `realpath --relative-to`...
# Luckily, we don't need to call tmux from other directories, so just make sure no one
# does by accident.
if test $PWD != $tmpdir
echo "error: isolated-tmux must always be run from the same directory." >&2
return 1
end
tmux -S .tmux-socket -f .tmux.conf $argv
end
function isolated-tmux-cleanup --on-event fish_exit --inherit-variable tmpdir
isolated-tmux kill-server
rm -r $tmpdir
end
function tmux-sleep
set -q CI && sleep 1
or sleep 0.3
end
function sleep-until
set -l cmd $argv[1]
set -l i 0
while [ $i -lt 100 ] && not eval "$cmd" >/dev/null
tmux-sleep
set i (math $i + 1)
end
if [ $i -eq 100 ]
printf '%s\n' "timeout waiting for $cmd" >&2
exit 1
end
end
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_prompt; printf "prompt $status_generation> "; end
# No autosuggestion from older history.
set fish_history ""
# No transient prompt.
set fish_transient_prompt 0
set -g CDPATH
' $argv
# Set the correct permissions for the newly created socket to allow future connections.
# This is required at least under WSL or else each invocation will return a permissions error.
chmod 777 .tmux-socket
# Resize window so we can attach to tmux session without changing panel size.
isolated-tmux resize-window $size
if test "$tmux_wait" = false
return
end
# Loop a bit, until we get an initial prompt.
for i in (seq 50)
if test -n "$(isolated-tmux capture-pane -p)"
return
end
sleep .2
end
echo "error: isolated-tmux-start timed out waiting for non-empty first prompt" >&2
end