mirror of
https://github.com/fish-shell/fish-shell.git
synced 2024-12-05 01:33:41 +08:00
417be25c69
Fixes #4435
(cherry picked from commit 1ef310c3a8
)
23 lines
807 B
Fish
23 lines
807 B
Fish
function export --description 'Set env variable. Alias for `set -gx` for bash compatibility.'
|
|
if not set -q argv[1]
|
|
set -x
|
|
return 0
|
|
end
|
|
for arg in $argv
|
|
set -l v (string split -m 1 "=" -- $arg)
|
|
switch (count $v)
|
|
case 1
|
|
set -gx $v $$v
|
|
case 2
|
|
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
|
|
# status is 1 from the contains check, and `set` does not change the status on success: reset it.
|
|
true
|
|
set -gx $v[1] $v[2]
|
|
end
|
|
end
|
|
end
|
|
end
|