2017-03-15 03:14:22 +08:00
|
|
|
function export --description 'Set env variable. Alias for `set -gx` for bash compatibility.'
|
2017-03-15 04:17:53 +08:00
|
|
|
if not set -q argv[1]
|
2017-03-15 03:14:22 +08:00
|
|
|
set -x
|
2015-10-12 17:35:45 +08:00
|
|
|
return 0
|
|
|
|
end
|
|
|
|
for arg in $argv
|
2016-02-11 03:33:43 +08:00
|
|
|
set -l v (string split -m 1 "=" -- $arg)
|
|
|
|
switch (count $v)
|
2015-10-12 17:35:45 +08:00
|
|
|
case 1
|
|
|
|
set -gx $v $$v
|
|
|
|
case 2
|
2017-02-10 20:25:32 +08:00
|
|
|
if contains -- $v[1] PATH CDPATH MANPATH
|
|
|
|
set -l colonized_path (string replace -- "$$v[1]" (string join ":" -- $$v[1]) $v[2])
|
|
|
|
set -gx $v[1] (string split ":" -- $colonized_path)
|
|
|
|
else
|
2017-10-01 16:08:10 +08:00
|
|
|
# status is 1 from the contains check, and `set` does not change the status on success: reset it.
|
|
|
|
true
|
2017-02-10 20:25:32 +08:00
|
|
|
set -gx $v[1] $v[2]
|
|
|
|
end
|
2014-11-28 19:48:11 +08:00
|
|
|
end
|
2015-10-12 17:35:45 +08:00
|
|
|
end
|
2014-11-28 19:48:11 +08:00
|
|
|
end
|