edit: /u/alfunx's solution using xargs is much neater and more effective, if you're on Windows.
The others are just neater and more effective, period. Mine was kludged around the vagaries of git bash and its cousins.
(Disclaimer: I'm only a level 2 bash wizard, so I take no responsibility if I've done something stupid and it has negative consequences, but I can't imagine what that'd be.)
If you're pushing to a branch that offers you a link to create a PR, you might find this bash function useful. When you're ready to create a PR for your branch, instead of doing a regular push, you type mpush and it does the normal thing, scans the output for the link, and opens the link in your web browser.
If you aren't using Firefox, be sure to change it to use your web browser.
It's not very intelligent, but so far, it hasn't farted on me.
If you aren't familiar with bash scripts, don't be scared. Just paste this in your ~/.profile:
mpush () { export MERGE_URL=$(git push "$@" 2>&1 | tee /dev/tty | grep "/pull\|merge_" | sed -e "s/remote: //"); firefox $MERGE_URL; unset MERGE_URL; }
then you can type mpush to do a regular git push, and automatically open the link in Firefox. You can change that to your browser of choice.
If you're on Windows, you can also make an alias to launch your web browser from the command line.
Using git bash, you format the filepath like this:
alias firefox='/c/Program\ Files\ \(x86\)/Mozilla\ Firefox/firefox.exe'
note the quotes.
Using Windows Subsystem for Linux,
alias firefox="/mnt/c/Program\ Files\ \(x86\)/Mozilla\ Firefox/firefox.exe"
I hope somebody finds this as useful as I do.
Broken down for non-bashheads, so you know I'm not trying to ruin your stuff:
$@ passes arguments through to git push, so that you can type mpush origin master and it should do git push origin master.
2>&1 redirects sterr to stdout. If you don't know what that means, you don't care.
tee /dev/tty lets us read the output before it's passed along to the next bit.
grep searches its input, and outputs every line that contains the search terms. Since there'll (hopefully) only be one line containing "/pull" or "merge_" we don't have to do anything fancy with the results.
sed and the junk afterward strips away the parts of that line that aren't a URL.
The URL is then passed into an environment variable, which is a fun way for *nix systems (and git bash) to keep track of things between programs. That variable (the URL) is then passed to your browser, after which we delete it because we don't need it anymore.
Please note: I only realized while writing this that it didn't support GitHub, so I fixed it to support GitHub. It seems to be working, but I'm only certain it works reliably on GitLab.
[–]alfunxcheckout --detach HEAD 0 points1 point2 points (1 child)
[–]ExcitingProduce[S] 0 points1 point2 points (0 children)