Last active
April 3, 2020 11:41
-
-
Save sjoerd-dijkstra/ebf9dee79d467b8b70cbdfe2757c5b51 to your computer and use it in GitHub Desktop.
Bash-like `export` method that handles lists, and additionally uses iTerms' SetUserVar
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
set -gx $v[1] $v[2] | |
printf "\033]1337;SetUserVar=%s=%s\007" "$v[1]" (printf "%s" "$v[2]" | base64 | tr -d "\n") | |
end | |
end | |
end | |
return 0 | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment