I'm an optimizer. Maybe an over-optimizer. If there are things I find myself doing all the time, even if they're fairly quick, I try to make them quicker so I spend less time doing the repetitive things I can do without thinking and more time thinking about the hard things (like naming things).
One thing I do all the time is open pull requests on Github. If I'm in bugfix mode, I can sometimes open 3 or 4 or more in a day (feature mode is slower of course). This isn't exactly a lengthy process, as my typical workflow is git add
, git commit
, git push
, then Cmd+Tab over to Chrome, Cmd+T to open a new tab, and type "git" in the omnibox. Because I go to https://github.com/mantacode/manta-frontend A LOT, only "g" is really needed to bring up this url, but I typically type "git" as it's the shortest complete syllable/phoneme in the word Github. Github, of course, provides a handy notification box for recently pushed branches that have no existing pull request, so you can just click on the button next to that and your done. But . . . I can make this better. Here's the bash function that does it:
# Open a pull request for the current branch
pr() {
# Get the current branch name from git
branch=$(git rev-parse --abbrev-ref HEAD)
# Open the (nicely reliable) url for a pull request to that branch
open https://github.com/mantacode/manta-frontend/compare/$branch?expand=1
}
That url is the url you land on when you click the little notification box "Pull request" button (but with the branch name instead of "$branch" of course). All I'm doing is navigating directly to that url and skipping all the steps of switching to Chrome, opening a new tab, etc. Obviously (I hope) replace "mantacode/manta-frontend" with whatever repository you contribute to (maybe you need to make pr
take a parameter if you contribute to many . . . or else grab the repo out of the remote).
On Mac, open [some url]
uses your default browser to open the link. On Linux, you'd need to have something like:
alias open="xdg-open"
in your bash aliases for this to work. On Windows, you'll want to switch to Mac or Linux. Seriously, just do it.
I suppose it's possible to make this even faster with a function that handles adding, committing, and pushing for you, but I like to make very atomic commits, so I don't often add/commit everything in one go. However, for you plucky risk-takers out there, I imagine it would look something like this:
feature() {
# Add all changes (including deletions) from the root
git add --all :/
git commit -m "$1"
# Assuming push.default is set to upstream.
# Otherwise, you need rev-parse to figure out
# what branch you're on, etc.
git push
pr
}
Note that that was invented on the spot and is thoroughly untested. Use at your own risk. I will be accepting all the credit if it goes off without a hitch and none of the blame if it deletes your entire hard drive and takes out your mailbox with a baseball bat. (But if that happens, let me know because that is interesting.)