Last active
October 28, 2015 00:25
-
-
Save joeheyming/5a3892afda9db4789987 to your computer and use it in GitHub Desktop.
This bash completion looks at the last few commits and allows you to tab complete the commit id. No more typing git push origin somecommit:master
This file contains hidden or 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
function pushCommit() { | |
git push origin $1:master; | |
} | |
function _pushCommit() { | |
local RECENT_COMMITS=`git log --pretty=oneline master..HEAD` | |
COMPREPLY=() | |
local cur | |
cur=$(_get_cword) | |
local OLDIFS="$IFS" | |
local IFS=$'\n' | |
COMPREPLY=( $( compgen -W "$RECENT_COMMITS" -- "$cur" ) ) | |
IFS="$OLDIFS" | |
if [[ ${#COMPREPLY[*]} -eq 1 ]]; then #Only one completion | |
COMPREPLY=( ${COMPREPLY[0]%% *} ) #Remove ' ' and everything after | |
fi | |
return 0 | |
} | |
complete -F _pushCommit pushCommit |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment