banner
Moraxyc

Moraxyc's Rhapsody

Passion Forever! 永远热爱!
twitter
telegram
github
medium
discord server

The Fuck? Save the clumsy party!

Fuck

Note
This article is a translation and simplification of the original document. In case of any conflicts, please refer to the original document!

Tip
Unless otherwise specified, all commands in this article work best in Debian/Ubuntu-based Linux distributions.

Requirements and Pain Points#

The best way to use a Linux system is naturally through the CLI. However, one major pain point of the CLI is the lack of a graphical interface! It's stating the obvious, but without a graphical interface, users have to type commands character by character. Due to the lack of a graphical interface, both experts and beginners occasionally make low-level errors such as misspelling or mistyping characters. However, unlike beginners, experts use command line shortcuts to quickly correct their mistakes. This article "Linux Command Line Editing Shortcuts" provides a detailed introduction to some command line shortcuts that assist Linux users in command operations.

But, I still find it troublesome to manually correct a long string of command results. It makes me want to exclaim, "Fuck!"

So, a dramatically named command was born: TheFuck

Features#

ExamplesThe following content is quoted from the original developer nvbn#

Example GIF

 apt-get install vim
E: Could not open lock file /var/lib/dpkg/lock - open (13: Permission denied)
E: Unable to lock the administration directory (/var/lib/dpkg/), are you root?

 fuck
sudo apt-get install vim [enter/↑/↓/ctrl+c]
[sudo] password for nvbn:
Reading package lists... Done
...
 git push
fatal: The current branch master has no upstream branch.
To push the current branch and set the remote as upstream, use

    git push --set-upstream origin master


 fuck
git push --set-upstream origin master [enter/↑/↓/ctrl+c]
Counting objects: 9, done.
...
 puthon
No command 'puthon' found, did you mean:
 Command 'python' from package 'python-minimal' (main)
 Command 'python' from package 'python3' (main)
zsh: command not found: puthon

 fuck
python [enter/↑/↓/ctrl+c]
Python 3.4.2 (default, Oct  8 2014, 13:08:17)
...
 git brnch
git: 'brnch' is not a git command. See 'git --help'.

Did you mean this?
    branch

 fuck
git branch [enter/↑/↓/ctrl+c]
* master
 lein rpl
'rpl' is not a task. See 'lein help'.

Did you mean this?
         repl

 fuck
lein repl [enter/↑/↓/ctrl+c]
nREPL server started on port 54848 on host 127.0.0.1 - nrepl://127.0.0.1:54848
REPL-y 0.3.1
...

If you don't mind blindly running the corrected command, you can disable the require_confirmation setting:

 apt-get install vim
E: Could not open lock file /var/lib/dpkg/lock - open (13: Permission denied)
E: Unable to lock the administration directory (/var/lib/dpkg/), are you root?

 fuck
sudo apt-get install vim
[sudo] password for nvbn:
Reading package lists... Done
...

Installation#

Dependencies#

The Fuck requires Python to run. The dependencies provided by nvbn are:

  • Python (3.4+)
  • pip
  • Python-dev

Installing Dependencies and The Fuck#

Install them using the following commands (for other Linux distributions, please refer to the original installation section):

sudo apt update
sudo apt install python3-dev python3-pip python3-setuptools
sudo pip3 install thefuck

The installation command in the original document adds the --user parameter at the end of the last command, which means The Fuck is installed in the .local/bin directory of the current user's home directory. You need to add the environment variable to run it. Here, I have made modifications to install the package directly under root or sudo, which skips this process.

Adding an Alias#

It is recommended to add the following command to .bash_profile, .bashrc, .zshrc, or other terminal startup scripts: eval $(thefuck --alias)

The Fuck now supports automatic addition, so you only need to enter fuck twice after installation.

Updating#

pip3 install thefuck --upgrade

Usage#

Fuck!#

After a command execution error, exclaim "Fuck" enter fuck, use the up and down keys to navigate the options, and press enter to confirm the correction.

Parameters#

  1. --yeah

fuck --yeah or fuck -y skips confirmation and executes the corrected command directly.

  1. -r

fuck -r makes The Fuck recursively correct and execute the command until the command is executed successfully.

Settings#

Configuration Options#

The Fuck's configuration file is located at ~/.config/thefuck/settings.py by default.

rules – List of enabled rules, defaults to thefuck.const.DEFAULT_RULES

exclude_rules – List of disabled rules, defaults to []

require_confirmation – Whether to require confirmation before running the corrected command, defaults to True

wait_command– Maximum time (in seconds) to wait for the output of the previous command

no_colors – Disable colored output

priority – Dictionary with rule priorities, where rules with lower priority will be matched first

debug – Whether to enable debug output, defaults to False

history_limit – How many history commands to scan, e.g., 2000

alter_history – Whether to add the corrected command to the history, defaults to True

wait_slow_command – Maximum time (in seconds) to wait for the output of the previous command if it is in the slow_commands list

slow_commands – List of slow commands

num_close_matches – Maximum number of command correction suggestions, defaults to 3.

excluded_search_path_prefixes – Prefixes of paths to ignore when searching for commands, defaults to [].

Instant Mode (Experimental)#

The default behavior of The Fuck requires time to rerun previous commands. In instant mode, The Fuck saves time by reading the log and continuing from the recorded output using a script.

Currently, instant mode only supports Python 3 with bash or zsh. The automatic correction feature of zsh also needs to be disabled for The Fuck to work properly.

To enable instant mode, add --enable-experimental-instant-mode to the alias parameters in terminal startup scripts such as .bashrc, .bash_profile, or .zshrc.

Here is an example:

eval $(thefuck --alias --enable-experimental-instant-mode)
Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.