The Fuck: fix the last command

terminalThere are a few ways to rectify specific issues with your last command like sudo !!. But how about a utility that could correct wrong commands or typos as well? Before proceeding further, I must state that I am not responsible for the NSFW name of the tool and would strongly suggest the author changes it to something civil. The Fuck is a useful python tool that can correct your last command and run it. It can work with bash, zsh or fish shells.

The utility tries to match rule for the last command, create a new command using matched rule and run it. The default enabled rules are git_no_command, git_push, no_command and sudo. However, it doesn’t stop there. You can add your custom rules. Sample rules can be found under ~/.thefuck/rules directory.

Installation

To install the utility:

$ sudo pip install thefuck

Add alias (as fix) in .bashrc or .zshrc:

alias fix='$(thefuck $(fc -ln -1))'

Or for fish shell in config.fish:

function fix
    eval (thefuck (history | head -n1))
end

Usage

Some examples:

$ apt-get install vim
error ...
$ fix
sudo apt-get install vim
...
$ puthon
error ...
$ fix
python
$ git push
error ...
$ fix
git push --set-upstream origin master

On GitHub: The Fuck

Comment

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s