skip to content
System Design in the Smoking Room
kevin
(AI translated)

Thefuck, or the best name a CLI ever had

/ 3 min read

Table of contents

TLDR

GitHub

Terminal window
# For macOS
brew install thefuck
# For Arch
sudo pacman -S thefuck

Somewhere in your .bashrc or .zshrc:

Terminal window
eval $(thefuck --alias)

Wat

A while back I came across an article about how much the small tools and “tricks” that make up a developer’s day-to-day actually matter. Whether that’s a helper like fzf or the one-off scripts you reach for to fix or sanity-check a microservice at work.

That really resonates with me. I’ve got a pile of aliases of my own that save me time every single day — the one I hit most often is gen_uuid:

Terminal window
gen_uuid() {
python3.11 -c "import uuid; print(uuid.uuid4())"
}
alias uuid="gen_uuid"

Super handy when you’re testing something against an API and need a random UUID — not the xkcd kind:

xkcd Random Number

python -c tricks in general are great for pulling out one or two lines of Python instead of saving a whole script somewhere just to call it later. Although maybe saving the script is the right call after all. Anthropic’s models, for one, keep handing me walls of code through python -c, except in their case it all comes wrapped in a metric ton of escaping, which makes it borderline unreadable at times. So, as always — with great power comes great responsibility.

But that’s not what this is about.

What I actually want to tell you about is one of my guilty pleasures that also happens to be a genuinely useful tool.

It’s a utility called thefuck.

At its core it’s a pile of heuristics that let you fix a typo or a broken command with one simple command:

Terminal window
fuck

Which is just genius! The author, as far as I can tell, is an English speaker, and I’d bet good money that word has been shouted across an office more than once.

Install it the usual way:

Terminal window
# For macOS
brew install thefuck
# For Arch
sudo pacman -S thefuck

Then add the init line to your .zshrc1:

Terminal window
eval $(thefuck --alias)

And then the magic happens — the heuristics work out what the command was supposed to be and drop in the right one.2

Example from the repo

My go-to case is pushing a new branch:

Git push

Yes, I know you can set up automatic remote creation in your git config. You can do all of it from an IDE. I don’t know — I giggle like Kevin from The Office every single time, and it’s genuinely handy for telling whether the branch already exists.

There’s plenty more to play with. By default thefuck waits for you to confirm the command before running it, but you can skip that prompt IN THE MOST AWESOME WAY POSSIBLE:

Terminal window
fuck --yeah

Or, if the corrected command might turn out to be wrong too, you can run it recursively:

Terminal window
fuck -r

You can always override the trigger keyword:

Terminal window
eval $(thefuck --alias BLYAT)

Or, if for some reason you need an SFW option3:

Terminal window
eval $(thefuck --alias оказия)
Okazia

You can also configure it further and write your own rules. Off the top of my head: on a VM, when you’re running out of disk space, print some advice straight into the terminal — do this, then that, then this other thing.

You can turn on EXPERIMENTAL INSTANT MODE so mistakes fix themselves on the spot.

There’s a ton of room to get creative here, and I think plenty of people would get some use out of it. Personally, I put it on every work machine I have. Maybe I should start putting it on VMs too…

So go on — use it, cringe at it, enjoy it. Here’s one more doodad for your toolbox!

Take care of yourself and the people close to you!

Footnotes

  1. Or wherever suits you. Classic case of: if it needs explaining, it doesn’t need explaining. ↩

  2. Someone’s bound to say it’s better to just set up an alias for your typos, but like everything else in this world, that’s a matter of taste. ↩

  3. оказия is an old-fashioned, slightly bookish Russian word for an unexpected turn of events — the sort of thing a very polite elderly neighbour says when the pipes burst: “well, what a to-do!” That’s the whole joke. Instead of barking fuck at your terminal, you calmly announce a minor inconvenience, and the exact same heuristics fix the exact same mistake — just with considerably more decorum. ↩