From 72a44460c6045750166d97775c64b74cacfbe34f Mon Sep 17 00:00:00 2001 From: Fabian Homborg Date: Sat, 30 May 2020 08:53:08 +0200 Subject: [PATCH] Move fish_greeting to a function This adds a "fish_greeting" function that prints the variable of the same name. In doing so, it makes $fish_greeting default to a global variable (this is of little cost because of the `_` builtin) This means that: - We have fewer universal variables by default - If we change the default greeting people will actually get - it (unless they have a leftover universal, of course) - If the user changes their language the variable changes with it --- .../functions/__fish_config_interactive.fish | 23 +++---------------- share/functions/fish_greeting.fish | 17 ++++++++++++++ 2 files changed, 20 insertions(+), 20 deletions(-) create mode 100644 share/functions/fish_greeting.fish diff --git a/share/functions/__fish_config_interactive.fish b/share/functions/__fish_config_interactive.fish index 7fb422d20..1bb79650f 100644 --- a/share/functions/__fish_config_interactive.fish +++ b/share/functions/__fish_config_interactive.fish @@ -19,17 +19,6 @@ function __fish_config_interactive -d "Initializations that should be performed set -g __fish_config_interactive_done set -g __fish_active_key_bindings - if not set -q fish_greeting - set -l line1 (_ 'Welcome to fish, the friendly interactive shell') - set -l line2 \n(printf (_ 'Type %shelp%s for instructions on how to use fish') (set_color green) (set_color normal)) - set -U fish_greeting "$line1$line2" - end - - if set -q fish_private_mode; and string length -q -- $fish_greeting - set -l line (_ "fish is running in private mode, history will not be persisted.") - set -g fish_greeting $fish_greeting.\n$line - end - # usage: __init_uvar VARIABLE VALUES... function __init_uvar -d "Sets a universal variable if it's not already set" if not set --query $argv[1] @@ -115,18 +104,12 @@ function __fish_config_interactive -d "Initializations that should be performed # # Print a greeting. - # fish_greeting can be a function (preferred) or a variable. + # The default just prints a variable of the same name. # # NOTE: This status check is necessary to not print the greeting when `read`ing in scripts. See #7080. if status --is-interactive - if functions -q fish_greeting - fish_greeting - else - # The greeting used to be skipped when fish_greeting was empty (not just undefined) - # Keep it that way to not print superfluous newlines on old configuration - test -n "$fish_greeting" - and echo $fish_greeting - end + and functions -q fish_greeting + fish_greeting end # diff --git a/share/functions/fish_greeting.fish b/share/functions/fish_greeting.fish new file mode 100644 index 000000000..2735b1c16 --- /dev/null +++ b/share/functions/fish_greeting.fish @@ -0,0 +1,17 @@ +function fish_greeting + if not set -q fish_greeting + set -l line1 (_ 'Welcome to fish, the friendly interactive shell') + set -l line2 \n(printf (_ 'Type %shelp%s for instructions on how to use fish') (set_color green) (set_color normal)) + set -g fish_greeting "$line1$line2" + end + + if set -q fish_private_mode + set -l line (_ "fish is running in private mode, history will not be persisted.") + set -g fish_greeting $fish_greeting.\n$line + end + + # The greeting used to be skipped when fish_greeting was empty (not just undefined) + # Keep it that way to not print superfluous newlines on old configuration + test -n "$fish_greeting" + and echo $fish_greeting +end