26 lines
605 B
Fish
Executable File
26 lines
605 B
Fish
Executable File
#!/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];
|
|
if set -q _flag_universal
|
|
# echo "set -U $argv[1] $argv[2..]" 1>&2
|
|
set -U $argv[1] $argv[2..]
|
|
else
|
|
# echo "set -g $argv[1] $argv[2..]" 1>&2
|
|
set -g $argv[1] $argv[2..]
|
|
end
|
|
end
|
|
end
|