Last active
April 27, 2016 21:12
-
-
Save DiegoSalazar/8a86f52e82d7492ebecc015b1c067ff4 to your computer and use it in GitHub Desktop.
Heroku bash helpers. Save this as a file in your home dir and source it in your .bash_profile
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
# | |
# Heroku helpers | |
# Example Usage: hcommand app-name | |
# | |
# open a Heroku rails console for an app | |
hcon() { | |
appName=$(ensureHasArg $1) | |
heroku run rails console -a $appName | |
} | |
# get the config for a Heroku app as shell vars | |
hconf() { | |
appName=$(ensureHasArg $1) | |
heroku config -s -a $appName | |
} | |
# tail the log of a Heroku app | |
hlog() { | |
appName=$(ensureHasArg $1) | |
heroku logs -t -a $appName | |
} | |
# run `rake db:migrate` on Heroku app | |
hmig() { | |
appName=$(ensureHasArg $1) | |
heroku run rake db:migrate -a $appName | |
} | |
# restart a Heroku app | |
hrestart() { | |
appName=$(ensureHasArg $1) | |
heroku restart -a $appName | |
} | |
# run a rake command on a Heroku app | |
# Usage: hrake app-name namespace:task | |
hrake() { | |
appName=$(ensureHasArg $1) | |
rakeCommand=$2 # rake command can't have spaces in it | |
if [ -z "$rakeCommand" ] | |
then | |
echo "provide a rake task name as a second argument" | |
return | |
fi | |
heroku run rake $rakeCommand -a $appName | |
} | |
# get the name of the last branch deployed to a Heroku app | |
# note: you must run this command from your local repo directory of the app. | |
# this command is useful for when you deploy feature branches that aren't master to | |
# your heroku app. This is done with the command syntax: `git push heroku feature_branch:master` | |
hlastbranch() { | |
appName=$(ensureHasArg $1) | |
commitId=$(heroku releases -n 1 -a $appName | grep Deploy | tr -s ' ' | cut -d ' ' -f3) | |
git branch --contains $commitId | |
} | |
# log into a dbconsole on a Heroku app | |
hdbcon() { | |
appName=$(ensureHasArg $1) | |
heroku run rails dbconsole -a $appName | |
} | |
ensureHasArg() { | |
if [ -z "$1" ] | |
then | |
echo "provide a Heroku App name: ${FUNCNAME[1]} app-name" 1>&2 | |
exit 1 | |
else | |
echo $1 | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment