setenv should behave like export

Fixes #3897
This commit is contained in:
Kurtis Rader 2017-03-14 12:14:22 -07:00
parent 7ab1c6c7ad
commit d9b30ab090
2 changed files with 22 additions and 6 deletions

View file

@ -1,6 +1,6 @@
function export --description 'Set global variable. Alias for set -gx, made for bash compatibility'
if test -z "$argv"
set
function export --description 'Set env variable. Alias for `set -gx` for bash compatibility.'
if not set -q argv[0]
set -x
return 0
end
for arg in $argv

View file

@ -1,4 +1,20 @@
function setenv --description 'Set global variable. Alias for set -g, made for csh compatibility'
set -gx $argv
function setenv --description 'Set env variable. Alias for `set -gx` for csh compatibility.'
if not set -q argv[0]
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
set -gx $v[1] $v[2]
end
end
end
end