2023-01-04 01:28:50 +00:00
|
|
|
#!/usr/bin/env fish
|
|
|
|
|
|
|
|
# set_default sets a variable with
|
|
|
|
# global scope (-g), if it is not already set
|
|
|
|
#
|
|
|
|
# Examples:
|
|
|
|
#
|
|
|
|
# set EXAMPLE_1 "hello"
|
|
|
|
# set_default EXAMPLE_1 "world"
|
|
|
|
# echo $EXAMPLE_1 # "hello"
|
|
|
|
#
|
|
|
|
# set_default EXAMPLE_2 "world"
|
|
|
|
# echo $EXAMPLE_2 # "world"
|
|
|
|
function set_default
|
|
|
|
argparse -i 'u/universal' -- $argv
|
|
|
|
if not set -q $argv[1];
|
2023-01-04 14:23:25 +00:00
|
|
|
if set -q _flag_universal
|
|
|
|
# echo "set -U $argv[1] $argv[2..]" 1>&2
|
2023-01-04 01:28:50 +00:00
|
|
|
set -U $argv[1] $argv[2..]
|
|
|
|
else
|
2023-01-04 14:23:25 +00:00
|
|
|
# echo "set -g $argv[1] $argv[2..]" 1>&2
|
2023-01-04 01:28:50 +00:00
|
|
|
set -g $argv[1] $argv[2..]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|