Alexander Dickson

Fix that last command

Have you ever accidentally typed something like…

$ git cehckout some-branch

Damn, you think to yourself, I should really be more careful! You think to how you could fix it and save the precious keystrokes.

  • The problem is not at the beginning or end so you can’t use !! and prepend/append.
  • The problem is mid way through the command so it’s not convenient to ctrl+a to jump the beginning and correct it, and ctrl+w would lose you that precious branch name you just freshly typed.
  • You haven’t installed thefuck. Maybe you should.

All hope is not lost though, as you can use the ^search^replace to correct the command. So, to correct the command you would simply type…

^cehck^check

Of course you could just use ^eh^he, but you run the risk of mangling other text in the command.

If you’re using ohmyzsh, and you should, you will even see a confirmation of the modified command, to ensure you don’t do anything dangerous.

Enjoy!


Want to discuss this post? Just mention me @alexdickson.