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.
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.
pip install thefuck
clink set history_io 1
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.
@echo off set PYTHONIOENCODING=utf-8 set PYTHONLEGACYWINDOWSSTDIO=yes 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
@echo off set PYTHONIOENCODING=utf-8 set PYTHONLEGACYWINDOWSSTDIO=yes 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.
After you restart your shell, running a failing command and
fuck should work as expected.