If you can also shake your hands and input the wrong command, you must recommend this fuck tool to you

Time:2021-11-24

[introduction]: the fuck is a command output verification tool, which can automatically check the input commands and execute the correct instructions. Probably as early as 2015.

brief introduction

The fuck is a powerful application that can proofread and correct command errors in the console. Its developers revealed that the design inspiration came from this twitter:

If you can also shake your hands and input the wrong command, you must recommend this fuck tool to you

Simple operation example:

If you can also shake your hands and input the wrong command, you must recommend this fuck tool to you

More examples:

➜ 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  
...  
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)  
...  

The project address is:https://github.com/nvbn/thefuck

Download and install

  • Dependence. The fuck running environment relies on Python 3.4 +, PIP and python dev.
  • Installation.

    1. OS X using homebrew installation:
brew install thefuck  
  1. Ubuntu/Mint:
sudo apt update  
sudo apt install python3-dev python3-pip python3-setuptools  
sudo pip3 install thefuck  
  1. FreeBSD:
pkg install thefuck  
  1. ChromeOS:
crew install thefuck  
  1. Other operating systems are installed using PIP:
pip install thefuck  
  1. Upgrade:
pip3 install thefuck --upgrade  

Action mechanism

The fuck attempts to match the wrong command with the rule. If a match is found, a new command is created and executed using the matching rule. There are many rules that can’t be listed one by one. Just list a few. If you are interested, please go to the official website.

  • adb\_ unknown\_ Command: a command that fixes spelling errors, such as ADB logcta
  • cat\_ Dir: replace cat with LS when trying to cat directory
  • cd\_ Parent: change CD.. to CD
  • docker\_ not\_ Command: fixed wrong docker commands, such as docker tags
  • git\_ branch\_ Delete: change git branch – D to git branch – D
  • go\_ unknown\_ Command: fix the wrong go command, such as go bulid
  • Java: delete the. Java extension when running Java programs. At the same time, the fuck also allows users to customize matching rules.
  • Create a rule violation file named your-rule-name.py in the \ ~ /. Config / thefuck / rules directory. The rule file must contain two functions:
match(command: Command) -> bool  
get_new_command(command: Command) -> str | list[str]  
  • Rules can contain optional functions:
side_effect(old_command: Command, fixed_command: str) -> None  

Open source outpostShare popular, interesting and practical open source projects on a daily basis. Participate in maintaining the open source technology resource library of 100000 + star, including python, Java, C / C + +, go, JS, CSS, node.js, PHP,. Net, etc.