nixpkgs/nixos/modules/programs/foot/config.fish
Steven Allen 32bf61c51e nixos/foot: only modify the prompt when running inside foot
Without this, these integration scripts will mess with the prompt even
when not running a shell inside of foot. This can break:

1. Terminals that don't understand these sequences (e.g., gnome-terminal
and likely other vte based terminals).
2. Anything that tries to parse the prompt (Emacs packages like
bash-completion).

This patch relies on the TERM variable (against upstream's
recommendation [1]) because:

1. Only Fish [2] has built-in support for querying things like
XTVERSION. Querying terminal features manually is non-trivial and
requires writing to STDOUT, which I'd like to avoid.

2. Even in Fish, this XTVERSION may only be queried after the first
prompt has been displayed ([2]), which is too late.

This patch does not explicitly check if the terminal is interactive as
the modified files are only sourced by interactive shells anyway.

[1]: https://codeberg.org/dnkl/foot#programmatically-checking-if-running-in-foot
[2]: https://fishshell.com/docs/current/cmds/status.html#status-terminal

fixes #374613
2026-06-23 13:49:26 -07:00

24 lines
634 B
Fish

if ! string match -q "foot*" "$TERM"
return 0
end
function update_cwd_osc --on-variable PWD --description 'Notify terminals when $PWD changes'
if status --is-command-substitution || set -q INSIDE_EMACS
return
end
printf \e\]7\;file://%s%s\e\\ $hostname (string escape --style=url $PWD)
end
update_cwd_osc # Run once since we might have inherited PWD from a parent shell
function mark_prompt_start --on-event fish_prompt
echo -en "\e]133;A\e\\"
end
function foot_cmd_start --on-event fish_preexec
echo -en "\e]133;C\e\\"
end
function foot_cmd_end --on-event fish_postexec
echo -en "\e]133;D\e\\"
end