30 lines
519 B
Bash
Executable file
30 lines
519 B
Bash
Executable file
#!/usr/bin/env bash
|
|
|
|
findenv() {
|
|
if [ -f ".env" ]; then
|
|
printf '%s\n' "${PWD%/}/.env"
|
|
elif [ "$PWD" = / ]; then
|
|
false
|
|
else
|
|
# a subshell so that we don't affect the caller's $PWD
|
|
(cd .. && findenv)
|
|
fi
|
|
}
|
|
|
|
env=$(findenv)
|
|
|
|
if [ -z "$env" ]; then
|
|
echo 'No .env file found'
|
|
exit 1
|
|
fi
|
|
|
|
connstr=$(rg '^DATABASE_URL=' "$env" | sed 's/.*=//')
|
|
|
|
if [ -z "$connstr" ]; then
|
|
echo "No DATABASE_URL found in $env"
|
|
exit 1
|
|
fi
|
|
|
|
export EDITOR=hx
|
|
export PSPG_CONF=~/.config/pspg/config
|
|
exec pgcli "$connstr"
|