Created
June 17, 2022 05:59
-
-
Save jercle/52de04288126f1c0721091cf7b13459f to your computer and use it in GitHub Desktop.
Environment Variable Setter - Adding to .zshrc
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
fex() { | |
if [ -z "$1" ]; then | |
if [ ! -f ~/.env ]; then | |
echo "~/.env not found!" | |
else | |
echo "Export the following from ~/.env:" | |
grep -v "^#" ~/.env | grep -v -e '^[[:space:]]*$' | |
export $(grep -v "^#" ~/.env | grep -v -e '^[[:space:]]*$' | xargs) | |
fi | |
else | |
if [[ "$1" == "mod" ]]; then | |
code ~/.env | |
elif [[ "$1" == "unset" ]]; then | |
if [ ! -f ~/.env ]; then | |
echo "./.env not found!" | |
else | |
echo "Unset the following from ~/.env:" | |
grep -v "^#" ~/.env | grep -v -e '^[[:space:]]*$' | sed -E "s/(.*)=.*/\1/" | |
unset $(grep -v "^#" ~/.env | grep -v -e '^[[:space:]]*$' | sed -E "s/(.*)=.*/\1/" | xargs) | |
fi | |
else | |
if [ -z "$2" ]; then | |
if [ ! -f "$1"/.env ]; then | |
echo "$1/.env not found!" | |
else | |
echo "Set the following from $1/.env:" | |
grep -v "^#" "$1"/.env | grep -v -e '^[[:space:]]*$' | |
export $(grep -v "^#" "$1"/.env | grep -v -e '^[[:space:]]*$' | xargs) | |
fi | |
else | |
if [[ "$2" == "unset" ]]; then | |
if [ ! -f "$1"/.env ]; then | |
echo "$1/.env not found!" | |
else | |
echo "Unset the following from $1/.env:" | |
grep -v "^#" "$1"/.env | grep -v -e '^[[:space:]]*$' | sed -E "s/(.*)=.*/\1/" | |
unset $(grep -v "^#" "$1"/.env | grep -v -e '^[[:space:]]*$' | sed -E "s/(.*)=.*/\1/" | xargs) | |
fi | |
elif [[ "$2" == "mod" ]]; then | |
code "$1"/.env | |
fi | |
fi | |
fi | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment