32bf61c51e
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
33 lines
741 B
Bash
33 lines
741 B
Bash
case "$TERM" in
|
|
foot*) : ;;
|
|
*) return 0 ;;
|
|
esac
|
|
|
|
osc7_cwd() {
|
|
local strlen=${#PWD}
|
|
local encoded=""
|
|
local pos c o
|
|
for (( pos=0; pos<strlen; pos++ )); do
|
|
c=${PWD:$pos:1}
|
|
case "$c" in
|
|
[-/:_.!\'\(\)~[:alnum:]] ) o="${c}" ;;
|
|
* ) printf -v o '%%%02X' "'${c}" ;;
|
|
esac
|
|
encoded+="${o}"
|
|
done
|
|
printf '\e]7;file://%s%s\e\\' "${HOSTNAME}" "${encoded}"
|
|
}
|
|
PROMPT_COMMAND=${PROMPT_COMMAND:+${PROMPT_COMMAND%;}; }osc7_cwd
|
|
|
|
prompt_marker() {
|
|
printf '\e]133;A\e\\'
|
|
}
|
|
PROMPT_COMMAND=${PROMPT_COMMAND:+${PROMPT_COMMAND%;}; }prompt_marker
|
|
|
|
PS0+='\e]133;C\e\\'
|
|
|
|
command_done() {
|
|
printf '\e]133;D\e\\'
|
|
}
|
|
PROMPT_COMMAND=${PROMPT_COMMAND:+${PROMPT_COMMAND%;}; }command_done
|