I have a different name for my heroku remote depending on the project, and I would like to have an alias for each of my projects to push to heroku, is there anyway to define an alias per folder, so that inside my project folder I can define the alias pointing to the right heroku remote?
I would suggest using a function instead of aliases.
# paths to projects
# - must be absolute
# - must not contain symlinks
# - must not end with "/"
# run `pwd -P` in the project root to get the correct value
PROJ_A="/path/to/project/a"
PROJ_B="/path/to/project/b"
pushit () {
case $(pwd -P) in
( $PROJ_A | $PROJ_A/* )
# Put command(s) needed to push A here
;;
( $PROJ_B | $PROJ_B/* )
# Put command(s) needed to push B here
;;
( * )
echo "You are not in a project directory"
;;
esac
}
Reasoning:
While it is possible to modify aliases every time the current working directory is changed by utilizing the chpwd
hook, you only need to know which command to use when you are actually pushing to heroku. So most of the time the aliases would be modified for nothing.
Using a function, the appropriate decisions can be made when you actually need it. And as all of the logic used in the function would be needed anyway when going the chpwd
route, so you actually reduce the lines of code needed when using the function directly.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With