How can I make git do the “did you mean” suggestion?

前端 未结 4 746
被撕碎了的回忆
被撕碎了的回忆 2021-01-30 04:36

I type

git puhs

And git says:

kristian@office:~/myrepo$ git puhs
git: \'puhs\' is not a git command. See \'git --help\'

Did y         


        
4条回答
  •  孤城傲影
    2021-01-30 05:32

    The autocorrect is nice, but my OCD-self needs a little more control over what's going on. So, I wrote a straightforward script that just chooses the first suggestion provided by git. You run the script after the failed command and use the built in bash history substitution "bang bang" syntax. Also, if you are typing something that could possibly have more than one command, this command lets you choose one other than the first option.

    It would look something like this,

    kristian@office:~/myrepo$ git puhs
    git: 'puhs' is not a git command. See 'git --help'
    
    Did you mean this?
          push
    
    kristian@office:~/myrepo$ idid !!
    Counting objects: 18, done.
    Delta compression using up to 32 threads.
    Compressing objects: 100% (10/10), done.
    Writing objects: 100% (10/10), 1.17 KiB, done.
    Total 10 (delta 6), reused 0 (delta 0)
    

    Plus, it's fun to type anything with two exclamation points. So bonus for that.

    Here's a gist with my script

提交回复
热议问题