Created
February 29, 2012 06:59
-
-
Save jasoncodes/1938675 to your computer and use it in GitHub Desktop.
Default `psql` to current Rails application
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
function __database_yml { | |
if [[ -f config/database.yml ]]; then | |
ruby -ryaml -rerb -e "puts YAML::load(ERB.new(IO.read('config/database.yml')).result)['${RAILS_ENV:-development}']['$1']" | |
fi | |
} | |
function psql | |
{ | |
if [[ "$(__database_yml adapter)" == 'postgresql' ]]; then | |
PGDATABASE="$(__database_yml database)" "$(/usr/bin/which psql)" "$@" | |
return $? | |
fi | |
"$(/usr/bin/which psql)" "$@" | |
} | |
export PSQL_EDITOR='vim +"set syntax=sql"' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment