Create a gist now

Instantly share code, notes, and snippets.

@papaben /idid.sh
Last active Apr 21, 2017

What would you like to do?
Run the git command you intended, `idid !!`
##
# "I did [mean that]"
# Re-run the suggested git command
# Intended to be run as 'idid "!!"'
# Place this file in your $PATH
# TODO create this as a brew script
##
declare last=''
declare selection_ordinal='1'
# Select something other than the first suggestion?
if [[ "$1" =~ "-" ]]; then
selection_ordinal="${1#-}"
shift
fi
while [[ $# > 0 ]]
do
last="$last $1"
shift
done
declare suggestion="$($last 2>&1)"
declare intended=$(echo "$suggestion" | grep -A $selection_ordinal 'Did you mean' | tail -1)
git $intended
Owner

papaben commented Jun 2, 2016 edited

Several folks use git autocorrect, but I don't trust that.

USAGE:

Parity with auto-correct

$ git dif
git: 'dfif' is not a git command. See 'git --help'.

Did you mean this?
        diff
> idid !!
<shows diff>

Choose non-default auto-correct suggestion

$ git pu
git: 'pu' is not a git command. See 'git --help'.

Did you mean one of these?
        pull
        push
        p4

$ idid -2 !!
<runs git push>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment