Created
July 12, 2014 13:07
-
-
Save Debilski/c0ed3f76839daa67674e to your computer and use it in GitHub Desktop.
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 bash_env --description 'Imports named variables from a bash script' | |
# Usage: | |
# bash_env script.bash VAR1 VAR2 VARN | |
# | |
set -l script $argv[1] | |
while read i; set code "$code""$i"\n; end < $script | |
set -l variables | |
for arg in $argv[2..-1] | |
set variables $variables "echo \"set -g $arg \${$arg}\""\n | |
end | |
set code "$code""$variables" | |
set res (bash -c $code) | |
echo "Importing" (count $res) "variable(s)" | |
for val in $res | |
echo "$val" | |
eval "$val" | |
end | |
end |
Author
Debilski
commented
Jul 12, 2014
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment