Skip to content

Instantly share code, notes, and snippets.

@papaben
Last active February 18, 2021 11:31
Show Gist options
  • Save papaben/463d72bb4ea329754566fa82ef0c949e to your computer and use it in GitHub Desktop.
Save papaben/463d72bb4ea329754566fa82ef0c949e to your computer and use it in GitHub Desktop.
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
@papaben
Copy link
Author

papaben commented Jun 2, 2016

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