mirror of
https://github.com/fish-shell/fish-shell
synced 2025-01-27 20:25:12 +00:00
cleanup some undefined var references
Testing a fix for #4163 revealed some questionable dereferencing of variables that are not certain to be defined.
This commit is contained in:
parent
7904f92c9e
commit
3284393aba
3 changed files with 40 additions and 26 deletions
|
@ -5,6 +5,8 @@
|
||||||
# Set default field separators
|
# Set default field separators
|
||||||
#
|
#
|
||||||
set -g IFS \n\ \t
|
set -g IFS \n\ \t
|
||||||
|
set -qg __fish_added_user_paths
|
||||||
|
or set -g __fish_added_user_paths
|
||||||
|
|
||||||
#
|
#
|
||||||
# Create the default command_not_found handler
|
# Create the default command_not_found handler
|
||||||
|
@ -175,13 +177,14 @@ end
|
||||||
# Invoke it immediately to apply the current value of fish_user_path
|
# Invoke it immediately to apply the current value of fish_user_path
|
||||||
function __fish_reconstruct_path -d "Update PATH when fish_user_paths changes" --on-variable fish_user_paths
|
function __fish_reconstruct_path -d "Update PATH when fish_user_paths changes" --on-variable fish_user_paths
|
||||||
set -l local_path $PATH
|
set -l local_path $PATH
|
||||||
set -l x
|
|
||||||
for x in $__fish_added_user_paths
|
for x in $__fish_added_user_paths
|
||||||
set -l idx (contains --index -- $x $local_path)
|
set -l idx (contains --index -- $x $local_path)
|
||||||
and set -e local_path[$idx]
|
and set -e local_path[$idx]
|
||||||
end
|
end
|
||||||
|
|
||||||
set -e __fish_added_user_paths
|
set -g __fish_added_user_paths
|
||||||
|
if set -q fish_user_paths
|
||||||
for x in $fish_user_paths[-1..1]
|
for x in $fish_user_paths[-1..1]
|
||||||
if set -l idx (contains --index -- $x $local_path)
|
if set -l idx (contains --index -- $x $local_path)
|
||||||
set -e local_path[$idx]
|
set -e local_path[$idx]
|
||||||
|
@ -190,8 +193,10 @@ function __fish_reconstruct_path -d "Update PATH when fish_user_paths changes" -
|
||||||
end
|
end
|
||||||
set local_path $x $local_path
|
set local_path $x $local_path
|
||||||
end
|
end
|
||||||
|
end
|
||||||
set -xg PATH $local_path
|
set -xg PATH $local_path
|
||||||
end
|
end
|
||||||
|
|
||||||
__fish_reconstruct_path
|
__fish_reconstruct_path
|
||||||
|
|
||||||
#
|
#
|
||||||
|
@ -230,22 +235,23 @@ end
|
||||||
# in UTF-8 (with non-ASCII characters).
|
# in UTF-8 (with non-ASCII characters).
|
||||||
__fish_set_locale
|
__fish_set_locale
|
||||||
|
|
||||||
# As last part of initialization, source the conf directories
|
# As last part of initialization, source the conf directories.
|
||||||
# Implement precedence (User > Admin > Extra (e.g. vendors) > Fish) by basically doing "basename"
|
# Implement precedence (User > Admin > Extra (e.g. vendors) > Fish) by basically doing "basename".
|
||||||
set -l sourcelist
|
set -l sourcelist
|
||||||
for file in $configdir/fish/conf.d/*.fish $__fish_sysconfdir/conf.d/*.fish $__extra_confdir/*.fish
|
for file in $configdir/fish/conf.d/*.fish $__fish_sysconfdir/conf.d/*.fish $__extra_confdir/*.fish
|
||||||
set -l basename (string replace -r '^.*/' '' -- $file)
|
set -l basename (string replace -r '^.*/' '' -- $file)
|
||||||
contains -- $basename $sourcelist
|
contains -- $basename $sourcelist
|
||||||
and continue
|
and continue
|
||||||
set sourcelist $sourcelist $basename
|
set sourcelist $sourcelist $basename
|
||||||
# Also skip non-files or unreadable files
|
# Also skip non-files or unreadable files.
|
||||||
# This allows one to use e.g. symlinks to /dev/null to "mask" something (like in systemd)
|
# This allows one to use e.g. symlinks to /dev/null to "mask" something (like in systemd).
|
||||||
[ -f $file -a -r $file ]
|
[ -f $file -a -r $file ]
|
||||||
and source $file
|
and source $file
|
||||||
end
|
end
|
||||||
|
|
||||||
# Upgrade pre-existing abbreviations from the old "key=value" to the new "key value" syntax
|
# Upgrade pre-existing abbreviations from the old "key=value" to the new "key value" syntax.
|
||||||
# This needs to be in share/config.fish because __fish_config_interactive is called after 2sourcing config.fish, which might contain abbr calls
|
# This needs to be in share/config.fish because __fish_config_interactive is called after sourcing
|
||||||
|
# config.fish, which might contain abbr calls.
|
||||||
if not set -q __fish_init_2_3_0
|
if not set -q __fish_init_2_3_0
|
||||||
set -l fab
|
set -l fab
|
||||||
for abb in $fish_user_abbreviations
|
for abb in $fish_user_abbreviations
|
||||||
|
@ -261,11 +267,9 @@ end
|
||||||
#
|
#
|
||||||
|
|
||||||
if status --is-login
|
if status --is-login
|
||||||
|
|
||||||
#
|
#
|
||||||
# Put linux consoles in unicode mode.
|
# Put linux consoles in unicode mode.
|
||||||
#
|
#
|
||||||
|
|
||||||
if test "$TERM" = linux
|
if test "$TERM" = linux
|
||||||
if string match -qir '\.UTF' -- $LANG
|
if string match -qir '\.UTF' -- $LANG
|
||||||
if command -sq unicode_start
|
if command -sq unicode_start
|
||||||
|
|
|
@ -255,13 +255,18 @@ function __fish_config_interactive -d "Initializations that should be performed
|
||||||
commandline -f repaint
|
commandline -f repaint
|
||||||
end
|
end
|
||||||
|
|
||||||
# Notify terminals when $PWD changes (issue #906)
|
# Notify terminals when $PWD changes (issue #906).
|
||||||
# VTE and Terminal.app support this in practice.
|
# VTE based terminals, Terminal.app, and iTerm.app support this.
|
||||||
if test "0$VTE_VERSION" -ge 3405 -o "$TERM_PROGRAM" = "Apple_Terminal"
|
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" -o "$TERM_PROGRAM" = "iTerm.app"
|
||||||
function __update_cwd_osc --on-variable PWD --description 'Notify capable terminals when $PWD changes'
|
function __update_cwd_osc --on-variable PWD --description 'Notify capable terminals when $PWD changes'
|
||||||
status --is-command-substitution
|
if status --is-command-substitution
|
||||||
or test -n "$INSIDE_EMACS"
|
or set -q INSIDE_EMACS
|
||||||
and return
|
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
|
end
|
||||||
__update_cwd_osc # Run once because we might have already inherited a PWD from an old tab
|
__update_cwd_osc # Run once because we might have already inherited a PWD from an old tab
|
||||||
|
|
|
@ -16,9 +16,11 @@ function __fish_set_locale
|
||||||
|
|
||||||
# We check LC_ALL to figure out if we have a locale but we don't set it later. That is because
|
# We check LC_ALL to figure out if we have a locale but we don't set it later. That is because
|
||||||
# locale.conf doesn't allow it so we should not set it.
|
# locale.conf doesn't allow it so we should not set it.
|
||||||
if string length -q -- $$LOCALE_VARS $LC_ALL
|
for locale_var in $LOCALE_VARS LC_ALL
|
||||||
|
if set -q $locale_var
|
||||||
return 0
|
return 0
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
# Unset all variables - they are empty anyway and this makes merging easier.
|
# Unset all variables - they are empty anyway and this makes merging easier.
|
||||||
for locale_var in $LOCALE_VARS
|
for locale_var in $LOCALE_VARS
|
||||||
|
@ -72,7 +74,10 @@ function __fish_set_locale
|
||||||
end
|
end
|
||||||
|
|
||||||
# If we really cannot get anything, at least set character encoding to UTF-8.
|
# If we really cannot get anything, at least set character encoding to UTF-8.
|
||||||
if not string length -q -- $$LOCALE_VARS $LC_ALL
|
for locale_var in $LOCALE_VARS LC_ALL
|
||||||
|
if set -q $locale_var
|
||||||
|
return 0
|
||||||
|
end
|
||||||
|
end
|
||||||
set -gx LC_CTYPE en_US.UTF-8
|
set -gx LC_CTYPE en_US.UTF-8
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
Loading…
Reference in a new issue