Files
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

30 lines
566 B
Bash

case "$TERM" in
foot*) : ;;
*) return 0 ;;
esac
function osc7-pwd() {
emulate -L zsh # also sets localoptions for us
setopt extendedglob
local LC_ALL=C
printf '\e]7;file://%s%s\e\' $HOST ${PWD//(#m)([^@-Za-z&-;_~])/%${(l:2::0:)$(([##16]#MATCH))}}
}
function chpwd-osc7-pwd() {
(( ZSH_SUBSHELL )) || osc7-pwd
}
function precmd {
if ! builtin zle; then
print -n "\e]133;D\e\\"
fi
print -Pn "\e]133;A\e\\"
}
function preexec {
print -n "\e]133;C\e\\"
}
autoload -U add-zsh-hook
add-zsh-hook -Uz chpwd chpwd-osc7-pwd