Skip to content

Instantly share code, notes, and snippets.

@joeheyming
Last active October 28, 2015 00:25
Show Gist options
  • Save joeheyming/5a3892afda9db4789987 to your computer and use it in GitHub Desktop.
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
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