Skip to content

Instantly share code, notes, and snippets.

@warmwaffles
Created April 4, 2021 15:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save warmwaffles/17a1947ca9c4dc49efee3b111cd52366 to your computer and use it in GitHub Desktop.
Save warmwaffles/17a1947ca9c4dc49efee3b111cd52366 to your computer and use it in GitHub Desktop.
Loads a dotenv file definition into the current fish shell
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