From d9b30ab09013ef803314d9656e669bc7577b585e Mon Sep 17 00:00:00 2001 From: Kurtis Rader Date: Tue, 14 Mar 2017 12:14:22 -0700 Subject: [PATCH] `setenv` should behave like `export` Fixes #3897 --- share/functions/export.fish | 6 +++--- share/functions/setenv.fish | 22 +++++++++++++++++++--- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/share/functions/export.fish b/share/functions/export.fish index 7d47b8e42..0c5561291 100644 --- a/share/functions/export.fish +++ b/share/functions/export.fish @@ -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 diff --git a/share/functions/setenv.fish b/share/functions/setenv.fish index 23cc94790..2141f4dad 100644 --- a/share/functions/setenv.fish +++ b/share/functions/setenv.fish @@ -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