Last active
February 20, 2022 13:40
-
-
Save amancevice/51fed600e10d3af1ea6d76aad0043d48 to your computer and use it in GitHub Desktop.
Source .env file into new shell
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
#!/bin/sh | |
function dotenv() { | |
dotfile="${1:-.env}" | |
# Error if file does not exist | |
if ! [ -f $dotfile ] ; then | |
echo "$dotfile: No such file or directory" >&2 | |
return 1 | |
fi | |
# Log | |
tput setaf 209 ; printf 'source ' >&2 | |
tput setaf 69 ; printf "$dotfile" >&2 | |
tput sgr0 ; echo >&2 | |
# Open new shell | |
$SHELL -c "set -o allexport ; source $dotfile ; set +o allexport ; $SHELL" | |
} | |
dotenv "$@" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment