mirror of
https://github.com/fish-shell/fish-shell
synced 2024-11-10 15:14:44 +00:00
Work around absent `string' in old fishies upgrading.
Improves experience during upgrades, accidentally running an old fish with a new environment. No errors just from printing a prompt. Fixes #3057. Print helpful notice also when launching mismatched fish. Autoloadable string.fish -- only create function if not builtin.
This commit is contained in:
parent
ecf4517ffe
commit
dfb4998778
4 changed files with 52 additions and 10 deletions
|
@ -18,17 +18,33 @@ function __fish_default_command_not_found_handler
|
|||
end
|
||||
|
||||
if status --is-interactive
|
||||
# Enable truecolor/24-bit support for select terminals
|
||||
if not set -q NVIM_LISTEN_ADDRESS # Neovim will swallow the 24bit sequences, rendering text white
|
||||
and begin
|
||||
set -q KONSOLE_PROFILE_NAME # KDE's konsole
|
||||
or string match -q -- "*:*" $ITERM_SESSION_ID # Supporting versions of iTerm2 will include a colon here
|
||||
or string match -q -- "st-*" $TERM # suckless' st
|
||||
or test "$VTE_VERSION" -ge 3600 # Should be all gtk3-vte-based terms after version 3.6.0.0
|
||||
or test "$COLORTERM" = truecolor -o "$COLORTERM" = 24bit # slang expects this
|
||||
# Existance of string is a good pre-2.3.0 check. Could also check $FISH_VERSION in the future.
|
||||
# This is a "launch", not an issue caused by autoloading during upgrades.
|
||||
if not contains "string" (builtin -n)
|
||||
# the string.fish message to `exec` will probably not help here, so this will that.
|
||||
set -g __is_launched_without_string 1
|
||||
|
||||
set_color --bold
|
||||
echo "You appear to be trying to launch an old fish binary with newer scripts "
|
||||
echo "installed into" (set_color --underline)"$__fish_datadir"
|
||||
set_color normal
|
||||
echo -e "\nThis is an unsupported configuration.\n"
|
||||
set_color yellow
|
||||
echo "You may need to uninstall and reinstall fish!"
|
||||
set_color normal
|
||||
else
|
||||
# Enable truecolor/24-bit support for select terminals
|
||||
if not set -q NVIM_LISTEN_ADDRESS # (Neovim will swallow the 24bit sequences, rendering text white)
|
||||
and begin
|
||||
set -q KONSOLE_PROFILE_NAME # KDE's konsole
|
||||
or string match -q -- "*:*" $ITERM_SESSION_ID # Supporting versions of iTerm2 will include a colon here
|
||||
or string match -q -- "st-*" $TERM # suckless' st
|
||||
or test "$VTE_VERSION" -ge 3600 # Should be all gtk3-vte-based terms after version 3.6.0.0
|
||||
or test "$COLORTERM" = truecolor -o "$COLORTERM" = 24bit # slang expects this
|
||||
end
|
||||
# Only set it if it isn't to allow override by setting to 0
|
||||
set -q fish_term24bit; or set -g fish_term24bit 1
|
||||
end
|
||||
# Only set it if it isn't to allow override by setting to 0
|
||||
set -q fish_term24bit; or set -g fish_term24bit 1
|
||||
end
|
||||
else
|
||||
# Hook up the default as the principal command_not_found handler
|
||||
|
|
|
@ -1,4 +1,8 @@
|
|||
function __fish_urlencode --description "URL-encode stdin"
|
||||
if not type -q string
|
||||
return 1
|
||||
end
|
||||
|
||||
set -l join ''
|
||||
set -l chars
|
||||
# Set locale to C and IFS to "" in order to split a line into bytes.
|
||||
|
|
|
@ -5,6 +5,12 @@ function prompt_pwd --description "Print the current working directory, shortene
|
|||
return 0
|
||||
end
|
||||
|
||||
# If we don't have a string builtin, we have no hope of maniuplating $PWD - just output it as-is.
|
||||
if not type -q string
|
||||
echo $PWD
|
||||
return 0
|
||||
end
|
||||
|
||||
# This allows overriding fish_prompt_pwd_dir_length from the outside (global or universal) without leaking it
|
||||
set -q fish_prompt_pwd_dir_length; or set -l fish_prompt_pwd_dir_length 1
|
||||
|
||||
|
|
16
share/functions/string.fish
Normal file
16
share/functions/string.fish
Normal file
|
@ -0,0 +1,16 @@
|
|||
if not contains string (builtin -n)
|
||||
function string
|
||||
if not set -q __is_launched_without_string
|
||||
if status --is-interactive
|
||||
# We've been autoloaded after fish < 2.3.0 upgraded to >= 2.3.1 - no string builtin
|
||||
set_color --bold
|
||||
echo "Fish has been upgraded, and the scripts on your system are not compatible"
|
||||
echo "with this prior instance of fish. You can probably run:"
|
||||
set_color green
|
||||
echo "\n exec fish"
|
||||
set_color normal
|
||||
echo "… to replace this process with a new one in-place."
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue