__fish_config_interactive: tighten up checks for OSC 7 feature

I spent some time figuring out $TERM_PROGRAM_VERSION and Terminal.app's
capabilities over time. [1]

Only use OSC 7 if running on the version of Terminal.app that added it
or newer. In the past this would have been harder because `test` couldn't
do float comparisons.

cleanup:
Don't bother setting a local $TERM_PROGRAM if it's unset: quoting
is enough to keep test happy. For the version numbers, 0"$var" is safe
against unset variables for numerical comparisons.

[1]: https://github.com/fish-shell/fish-shell/wiki/Terminal.app-characteristics
This commit is contained in:
Aaron Gyes
2018-12-14 04:46:14 -08:00
parent f8338d63ed
commit ba9c387590

View File

@@ -271,18 +271,14 @@ function __fish_config_interactive -d "Initializations that should be performed
end
# Notify terminals when $PWD changes (issue #906).
# VTE based terminals, Terminal.app, and iTerm.app support this.
set -q VTE_VERSION
or set -l VTE_VERSION 0
set -q TERM_PROGRAM
or set -l TERM_PROGRAM
if test "$VTE_VERSION" -ge 3405 -o "$TERM_PROGRAM" = "Apple_Terminal"
# VTE based terminals, Terminal.app , and iTerm.app support this.
if test 0"$VTE_VERSION" -ge 3405 -o "$TERM_PROGRAM" = "Apple_Terminal" -a 0"$TERM_PROGRAM_VERSION" -ge 309
function __update_cwd_osc --on-variable PWD --description 'Notify capable terminals when $PWD changes'
if status --is-command-substitution
or set -q INSIDE_EMACS
return
end
printf \e\]7\;file://\%s\%s\a $hostname (string escape --style=url $PWD)
printf \e\]7\;file://%s%s\a $hostname (string escape --style=url $PWD)
end
__update_cwd_osc # Run once because we might have already inherited a PWD from an old tab
end