Skip to content

Instantly share code, notes, and snippets.

@jasoncodes
Created February 29, 2012 06:59
Show Gist options
  • Save jasoncodes/1938675 to your computer and use it in GitHub Desktop.
Save jasoncodes/1938675 to your computer and use it in GitHub Desktop.
Default `psql` to current Rails application
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