From 3284393aba3ae36dea641738cb7e0b5fe0ca1b69 Mon Sep 17 00:00:00 2001 From: Kurtis Rader Date: Sat, 1 Jul 2017 20:45:30 -0700 Subject: [PATCH] cleanup some undefined var references Testing a fix for #4163 revealed some questionable dereferencing of variables that are not certain to be defined. --- share/config.fish | 36 ++++++++++--------- .../functions/__fish_config_interactive.fish | 17 +++++---- share/functions/__fish_set_locale.fish | 13 ++++--- 3 files changed, 40 insertions(+), 26 deletions(-) diff --git a/share/config.fish b/share/config.fish index b63fe6bd3..58dcd8702 100644 --- a/share/config.fish +++ b/share/config.fish @@ -5,6 +5,8 @@ # Set default field separators # 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 @@ -175,23 +177,26 @@ end # 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 set -l local_path $PATH - set -l x + for x in $__fish_added_user_paths set -l idx (contains --index -- $x $local_path) and set -e local_path[$idx] end - set -e __fish_added_user_paths - for x in $fish_user_paths[-1..1] - if set -l idx (contains --index -- $x $local_path) - set -e local_path[$idx] - else - set -g __fish_added_user_paths $__fish_added_user_paths $x + set -g __fish_added_user_paths + if set -q fish_user_paths + for x in $fish_user_paths[-1..1] + if set -l idx (contains --index -- $x $local_path) + set -e local_path[$idx] + else + set -g __fish_added_user_paths $__fish_added_user_paths $x + end + set local_path $x $local_path end - set local_path $x $local_path end set -xg PATH $local_path end + __fish_reconstruct_path # @@ -230,22 +235,23 @@ end # in UTF-8 (with non-ASCII characters). __fish_set_locale -# As last part of initialization, source the conf directories -# Implement precedence (User > Admin > Extra (e.g. vendors) > Fish) by basically doing "basename" +# As last part of initialization, source the conf directories. +# Implement precedence (User > Admin > Extra (e.g. vendors) > Fish) by basically doing "basename". set -l sourcelist for file in $configdir/fish/conf.d/*.fish $__fish_sysconfdir/conf.d/*.fish $__extra_confdir/*.fish set -l basename (string replace -r '^.*/' '' -- $file) contains -- $basename $sourcelist and continue set sourcelist $sourcelist $basename - # Also skip non-files or unreadable files - # This allows one to use e.g. symlinks to /dev/null to "mask" something (like in systemd) + # Also skip non-files or unreadable files. + # This allows one to use e.g. symlinks to /dev/null to "mask" something (like in systemd). [ -f $file -a -r $file ] and source $file end -# 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 +# 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 sourcing +# config.fish, which might contain abbr calls. if not set -q __fish_init_2_3_0 set -l fab for abb in $fish_user_abbreviations @@ -261,11 +267,9 @@ end # if status --is-login - # # Put linux consoles in unicode mode. # - if test "$TERM" = linux if string match -qir '\.UTF' -- $LANG if command -sq unicode_start diff --git a/share/functions/__fish_config_interactive.fish b/share/functions/__fish_config_interactive.fish index 0b7099270..697a68276 100644 --- a/share/functions/__fish_config_interactive.fish +++ b/share/functions/__fish_config_interactive.fish @@ -255,13 +255,18 @@ function __fish_config_interactive -d "Initializations that should be performed commandline -f repaint end - # Notify terminals when $PWD changes (issue #906) - # VTE and Terminal.app support this in practice. - if test "0$VTE_VERSION" -ge 3405 -o "$TERM_PROGRAM" = "Apple_Terminal" + # 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" -o "$TERM_PROGRAM" = "iTerm.app" function __update_cwd_osc --on-variable PWD --description 'Notify capable terminals when $PWD changes' - status --is-command-substitution - or test -n "$INSIDE_EMACS" - and return + 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) end __update_cwd_osc # Run once because we might have already inherited a PWD from an old tab diff --git a/share/functions/__fish_set_locale.fish b/share/functions/__fish_set_locale.fish index 1950dabb0..125b79d08 100644 --- a/share/functions/__fish_set_locale.fish +++ b/share/functions/__fish_set_locale.fish @@ -16,8 +16,10 @@ 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 # locale.conf doesn't allow it so we should not set it. - if string length -q -- $$LOCALE_VARS $LC_ALL - return 0 + for locale_var in $LOCALE_VARS LC_ALL + if set -q $locale_var + return 0 + end end # Unset all variables - they are empty anyway and this makes merging easier. @@ -72,7 +74,10 @@ function __fish_set_locale end # If we really cannot get anything, at least set character encoding to UTF-8. - if not string length -q -- $$LOCALE_VARS $LC_ALL - set -gx LC_CTYPE en_US.UTF-8 + 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 end