How to auto-correct typos in your commands in the terminal

There is an auto-correct library that is useful for quickly correcting commands written into the terminal and they can be run without the typo’s.

This library is called thefuck, the tool is available from the github page.

thefuck-github.png

How to install on MacOS

This guide will require brew to be installed, more information on brew can be found at the brew.sh website.

Use the brew install command to install thefuck.

brew install thefuck

Add the following to either a .bash_profile or .zshrc file so the command runs every time you access the terminal.

eval $(thefuck --alias)

After installation try calling thefuck using the below command.

fuck

You should see the following response output.

No fucks given

How to use

This tool is used whenever you make a mistake with your unix commands in the terminal.

Here is an example of using the cat index.tsx command except it has a typo so that I can make use of the fuck command to auto-correct the prior command to the correct form.

thefuck-usage.png

So use the fuck command after making the mistake, select the correct command and press enter. The command will then be run successfully.

Install issues on Linux (Ubuntu 24.04)

II currently use Ubuntu 24.04 for my desktop PC and I’ve had issues installed thefuck onto it. The reason why is because the latest version of python (3.12) isn’t compatible with thefuck. So far the only solution I’ve found is to downgrade Python back down to 3.11 but I may find another solution on Linux.