Created
April 4, 2021 15:05
-
-
Save warmwaffles/17a1947ca9c4dc49efee3b111cd52366 to your computer and use it in GitHub Desktop.
Loads a dotenv file definition into the current fish shell
This file contains hidden or 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 dotenv -a filePath -d 'exports all .env entries to global' | |
if not test -f $filePath | |
echo Error: file $filePath does not exist or can not be read | |
return | |
end | |
echo Parsing dotenv file $filePath | |
for entry in (cat $filePath | grep -v '^#' | grep -v '^$') | |
set entry = (string split -m 1 \= -- $entry) | |
set key $entry[2] | |
set value (echo -e $entry[3] | string trim -c "'" | tr '\0' '\n' | sed "s|~|$HOME|g") | |
echo Setting (set_color brcyan)$key(set_color normal) | |
set -e $key | |
set -xg $key $value | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment