Nathan Smith

Using thefuck On Windows, With Clink & Cmder

August 14, 2018, 3:16 PM—Devtools

We all make mistakes, and sometimes we get angry about them. thefuck is a handy Python script that turns that anger into something useful by suggesting a correction to a previously failed command.

thefuck Example
thefuck Example

So, lets make it work on Windows, which will require Clink or Cmder. Clink adds some Unix-like features to the Windows command prompt, while Cmder is a package that includes Clink along with a number of other applications to provide a complete terminal solution for Windows. Both are free, and Cmder is always one of the first things I install on a new computer. It's really the best way to use the terminal on Windows. Lets get started. Caveat: this is probably not the best way to make this work, but it's what I came up with while bored at work.


  1. Install Clink, or better yet, Cmder.
  2. Install thefuck with pip: pip install thefuck
  3. Enable Clink history: clink set history_io 1

Create the Alias

thefuck works by having platform specific aliases to get the last run command, fix your mistake, and then run the fixed command. Because there's no Windows specific alias (excluding PowerShell, which can be setup following these directions), we have to make our own. Save this file as thefuckcmder.bat or some other .bat filename. Remember where you save it or ensure it's available in your PATH.

For Clink

@echo off
tail -n 2 %LOCALAPPDATA%\clink\.history | head -n 1 > %LOCALAPPDATA%\clink\fucked_cmd.txt
set /p fucked_cmd=<%LOCALAPPDATA%\clink\fucked_cmd.txt
thefuck %fucked_cmd% > %LOCALAPPDATA%\clink\unfucked.cmd
call %LOCALAPPDATA%\clink\unfucked.cmd

For Cmder

@echo off
tail -n 2 %CMDER_ROOT%\config\.history | head -n 1 > %CMDER_ROOT%\config\fucked_cmd.txt
set /p fucked_cmd=<%CMDER_ROOT%\config\fucked_cmd.txt
thefuck %fucked_cmd% > %CMDER_ROOT%\config\unfucked.cmd
call %CMDER_ROOT%\config\unfucked.cmd

Now we have to create the alias that calls that script, replacing 'thefuckcmder' with the path to your script.

For Clink

doskey fuck=thefuckcmder

For Cmder

alias fuck=thefuckcmder

After you restart your shell, running a failing command and fuck should work as expected.

Next: Metal & Synthwave are the Same Thing

Homebrewery Markdown Preview