Created
March 6, 2019 07:11
-
-
Save borissov/61e2e312bb943bd802d2736de02b1086 to your computer and use it in GitHub Desktop.
Wrapper to open ".env" files with MyCLI or PgCLI. Search in parent directories.
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/bash | |
function dbe() { | |
local slashes=${PWD//[^\/]/} | |
local directory="$PWD" | |
for (( n=${#slashes}; n>0; --n )) | |
do | |
if [ -f "$directory/.env" ]; then | |
echo -e "Load file:\\033[0;31m$(readlink -f -- "$directory/.env") \\033[0m" | |
while read p; do | |
if [ -n "$p" ]; then | |
eval "local $p" | |
fi | |
done <"$directory/.env" | |
if [ $DB_CONNECTION="mysql" ]; then | |
mycli $DB_DATABASE -h $DB_HOST -u $DB_USERNAME -p$DB_PASSWORD | |
else | |
pgcli $DB_DATABASE -h $DB_HOST -u $DB_USERNAME -p$DB_PASSWORD | |
fi | |
return | |
fi | |
directory="$directory/.." | |
done | |
echo ".env file not found." | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment