Fetching contributors…
Cannot retrieve contributors at this time
53 lines (44 sloc) 2.12 KB
#!/usr/bin/env bash
# Wrap 'git' with 'hub' - if we have hub installed.
if [ -x "$(command -v hub)" ]; then
eval "$(hub alias -s)"
# Not really a command, but a much nicer version of git branch.
# Source:
alias gbranch='for k in `git branch -l | \
perl -pe '\''s/^..(.*?)( ->.*)?$/\1/'\''`; \
do echo -e `git show --pretty=format:"%Cgreen%ci %Cblue%cr%Creset" $k -- | \
head -n 1`\\t$k; done | sort -r'
alias gbranchr='for k in `git branch -r | \
perl -pe '\''s/^..(.*?)( ->.*)?$/\1/'\''`; \
do echo -e `git show --pretty=format:"%Cgreen%ci %Cblue%cr%Creset" $k -- | \
head -n 1`\\t$k; done | sort -r'
# Push to origin. Use it all the time innit?
alias gpo='git push --set-upstream origin $(git_current_branch)'
# Colour constants for nicer output.
# Push the current branch to origin, set upstream, open the PR page if possible.
# Inspired by:
# How to get the current branch:
# How to open the browser:
gpr() {
# Get the current branch name, or use 'HEAD' if we cannot get it.
branch=$(git symbolic-ref -q HEAD)
# Pushing take a little while, so let the user know we're working.
echo "Opening pull request for ${GREEN}${branch}${RESET}..."
# Push to origin, grabbing the output but then echoing it back.
push_output=`git push origin -u ${branch} 2>&1`
echo ""
echo ${push_output}
# If there's anything which starts with http, it's a good guess it'll be a
# link to GitHub/GitLab/Whatever. So open it.
link=$(echo ${push_output} | grep -o 'http.*' | sed -e 's/[[:space:]]*$//')
if [ ${link} ]; then
echo ""
echo "Opening: ${GREEN}${link}${RESET}..."
python -mwebbrowser ${link}