Skip to content

Instantly share code, notes, and snippets.

@borissov
Created March 6, 2019 07:11
Show Gist options
  • Save borissov/61e2e312bb943bd802d2736de02b1086 to your computer and use it in GitHub Desktop.
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.
#!/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