thefuck README

The project's README from github.com/nvbn/thefuck. As one markdown file: README.md.

The Fuck [![Version][version-badge]][version-link] [![Build Status][workflow-badge]][workflow-link] [![Coverage][coverage-badge]][coverage-link] ![MIT License][license-badge]

The Fuck is a magnificent app, inspired by a @liamosaur tweet, that corrects errors in previous console commands.

Is The Fuck too slow? Try the experimental instant mode!

[![gif with examples][examples-link]][examples-link]

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
...
➜ 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're not afraid of blindly running corrected commands, the require_confirmation settings option can be disabled:

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

Contents

  1. Requirements
  2. Installations
  3. Updating
  4. How it works
  5. Creating your own rules
  6. Settings
  7. Third party packages with rules
  8. Experimental instant mode
  9. Developing
  10. License

Requirements

Back to Contents

Installation

On macOS or Linux, you can install The Fuck via [Homebrew][homebrew]:

brew install thefuck

On Ubuntu / Mint, install The Fuck with the following commands:

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

On FreeBSD, install The Fuck with the following commands:

pkg install thefuck

On ChromeOS, install The Fuck using chromebrew with the following command:

crew install thefuck

On Arch based systems, install The Fuck with the following command:

sudo pacman -S thefuck

On other systems, install The Fuck by using pip:

pip install thefuck

Alternatively, you may use an OS package manager (OS X, Ubuntu, Arch).

# It is recommended that you place this command in your .bash_profile, .bashrc, .zshrc or other startup script:

eval $(thefuck --alias)
# You can use whatever you want as an alias, like for Mondays:
eval $(thefuck --alias FUCK)

Or in your shell config (Bash, Zsh, Fish, Powershell, tcsh).

Changes are only available in a new shell session. To make changes immediately available, run source ~/.bashrc (or your shell config file like .zshrc).

To run fixed commands without confirmation, use the --yeah option (or just -y for short, or --hard if you're especially frustrated):

fuck --yeah

To fix commands recursively until succeeding, use the -r option:

fuck -r
Back to Contents

Updating

pip3 install thefuck --upgrade

Note: Alias functionality was changed in v1.34 of The Fuck

Uninstall

To remove The Fuck, reverse the installation process:

How it works

The Fuck attempts to match the previous command with a rule. If a match is found, a new command is created using the matched rule and executed. The following rules are enabled by default:

Back to Contents

The following rules are enabled by default on specific platforms only:

The following commands are bundled with The Fuck, but are not enabled by default:

Back to Contents

Creating your own rules

To add your own rule, create a file named your-rule-name.py in ~/.config/thefuck/rules. The rule file must contain two functions:

match(command: Command) -> bool
get_new_command(command: Command) -> str | list[str]

Additionally, rules can contain optional functions:

side_effect(old_command: Command, fixed_command: str) -> None

Rules can also contain the optional variables enabled_by_default, requires_output and priority.

Command h

thefuck (nvbn/thefuck)

Searching Database…

97.9K ·GitHub
这是什么?The Fuck 是一个命令行应用,用于修正你上一条输错的控制台命令。命令失败后运行 'fuck',它会给出修正后的版本供你执行。
它是独立程序还是 shell 插件?它是一个 Python 命令行工具,需要在你的 shell 配置文件中设置别名(支持 Bash、Zsh、Fish、PowerShell、tcsh)。之后输入 'fuck',就会根据 shell 历史记录重新运行别名对应的逻辑。
我该如何安装和设置?在 macOS/Linux 上通过 Homebrew 安装,在 Ubuntu/Mint 上通过 apt/pip 安装,其他系统使用 pip,或使用发行版自带的包管理器安装。然后将别名配置行添加到 shell 启动文件中,并重新加载 shell。
安装前我需要准备什么?需要先安装 Python 3.5+、pip 和 python-dev。
它建议的每个修正我都需要确认吗?默认情况下,运行修正后的命令前会要求确认。你可以用 --yeah/-y 参数跳过确认,也可以通过设置完全关闭确认。-r 参数会递归重试,直到成功为止。
它支持哪些 shell?支持 Bash、Zsh、Fish、PowerShell 和 tcsh,运行于 macOS、Linux、FreeBSD 和 ChromeOS 上。
它如何决定修正方案?它会将你上一条失败的命令与内置的大型规则库进行匹配(例如 git、docker、npm、pip、cd 的拼写错误等)。如果匹配到规则,就会生成修正后的命令并运行。
有即时模式或更快的模式吗?有。它提供一个实验性的即时模式,如果常规流程感觉太慢,可以用它加快建议的生成速度。
我可以编写自己的修正规则吗?可以。README 中有一节“Creating your own rules”(创建自己的规则)的说明,此外还有第三方软件包可以添加额外的规则。
它能修正哪些类型的错误?内置有数百条规则,涵盖 git、docker、npm、pip、apt、go、cargo、mvn、grep、cd、ls 以及许多其他常用命令行工具中的拼写错误。例如修正 'git brnch',或在权限被拒绝时添加 'sudo'。
What are similar projects?git-extras, autojump, tmuxinator, n, oh-my-posh, diff-so-fancy, just, hub
Creator
nvbn
Size
3.9 MB
Stars
97.9K
Age
11y
Commits · 90 Days