1
0
mirror of https://github.com/nvbn/thefuck.git synced 2024-10-05 18:31:10 +01:00
thefuck/README.md

556 lines
25 KiB
Markdown
Raw Normal View History

# The Fuck [![Version][version-badge]][version-link] [![Build Status][workflow-badge]][workflow-link] [![Coverage][coverage-badge]][coverage-link] [![MIT License][license-badge]](LICENSE.md)
2015-04-08 17:15:49 +01:00
*The Fuck* is a magnificent app, inspired by a [@liamosaur](https://twitter.com/liamosaur/)
[tweet](https://twitter.com/liamosaur/status/506975850596536320),
that corrects errors in previous console commands.
2015-04-08 17:15:49 +01:00
Is *The Fuck* too slow? [Try the experimental instant mode!](#experimental-instant-mode)
2017-08-26 12:31:09 +01:00
2016-04-01 01:48:22 +01:00
[![gif with examples][examples-link]][examples-link]
2015-07-19 19:53:08 +01:00
More examples:
2015-04-08 17:15:49 +01:00
```bash
➜ 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
2015-07-31 13:36:08 +01:00
sudo apt-get install vim [enter/↑/↓/ctrl+c]
[sudo] password for nvbn:
2015-04-08 17:15:49 +01:00
Reading package lists... Done
...
```
2015-04-08 17:15:49 +01:00
```bash
2015-04-08 17:15:49 +01:00
➜ 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
2015-07-31 13:36:08 +01:00
git push --set-upstream origin master [enter/↑/↓/ctrl+c]
2015-04-08 17:15:49 +01:00
Counting objects: 9, done.
...
```
2015-04-08 18:00:03 +01:00
```bash
2015-04-08 18:00:03 +01:00
➜ 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
2015-07-31 13:36:08 +01:00
python [enter/↑/↓/ctrl+c]
2015-04-08 18:00:03 +01:00
Python 3.4.2 (default, Oct 8 2014, 13:08:17)
...
```
2015-04-08 20:20:11 +01:00
```bash
2015-04-08 20:20:11 +01:00
➜ git brnch
git: 'brnch' is not a git command. See 'git --help'.
Did you mean this?
2016-03-24 01:47:09 +00:00
branch
2015-04-08 20:20:11 +01:00
➜ fuck
2015-07-31 13:36:08 +01:00
git branch [enter/↑/↓/ctrl+c]
2015-04-08 20:20:11 +01:00
* master
```
2015-04-18 22:19:34 +01:00
```bash
2015-04-18 22:19:34 +01:00
➜ lein rpl
'rpl' is not a task. See 'lein help'.
Did you mean this?
repl
➜ fuck
2015-07-31 13:36:08 +01:00
lein repl [enter/↑/↓/ctrl+c]
2015-04-18 22:19:34 +01:00
nREPL server started on port 54848 on host 127.0.0.1 - nrepl://127.0.0.1:54848
REPL-y 0.3.1
...
2015-04-08 17:15:49 +01:00
```
If you're not afraid of blindly running corrected commands, the
`require_confirmation` [settings](#settings) option can be disabled:
2015-04-21 04:30:15 +01:00
```bash
➜ 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
2015-04-21 04:30:15 +01:00
[sudo] password for nvbn:
Reading package lists... Done
...
```
## Contents
2021-03-13 11:47:55 +00:00
1. [Requirements](#requirements)
2. [Installations](#installation)
3. [Updating](#updating)
4. [How it works](#how-it-works)
5. [Creating your own rules](#creating-your-own-rules)
6. [Settings](#settings)
7. [Third party packages with rules](#third-party-packages-with-rules)
8. [Experimental instant mode](#experimental-instant-mode)
9. [Developing](#developing)
10. [License](#license-mit)
## Requirements
- python (3.4+)
- pip
- python-dev
2021-03-13 11:47:55 +00:00
##### [Back to Contents](#contents)
## Installation
2015-08-24 18:25:59 +01:00
On OS X, you can install *The Fuck* via [Homebrew][homebrew] (or via [Linuxbrew][linuxbrew] on Linux):
```bash
brew install thefuck
```
On Ubuntu / Mint, install *The Fuck* with the following commands:
2016-05-09 16:54:40 +01:00
```bash
sudo apt update
sudo apt install python3-dev python3-pip python3-setuptools
sudo pip3 install thefuck
2016-05-09 16:54:40 +01:00
```
2015-04-08 17:15:49 +01:00
On FreeBSD, install *The Fuck* with the following commands:
```bash
pkg install thefuck
```
2018-05-10 00:35:46 +01:00
On ChromeOS, install *The Fuck* using [chromebrew](https://github.com/skycocker/chromebrew) with the following command:
```bash
crew install thefuck
```
On other systems, install *The Fuck* by using `pip`:
2015-04-08 17:15:49 +01:00
```bash
pip install thefuck
2015-04-08 17:15:49 +01:00
```
[Alternatively, you may use an OS package manager (OS X, Ubuntu, Arch).](https://github.com/nvbn/thefuck/wiki/Installation)
2015-04-22 22:00:18 +01:00
2017-09-27 17:21:07 +01:00
<a href='#manual-installation' name='manual-installation'>#</a>
It is recommended that you place this command in your `.bash_profile`,
`.bashrc`, `.zshrc` or other startup script:
2015-04-08 17:15:49 +01:00
```bash
eval $(thefuck --alias)
# You can use whatever you want as an alias, like for Mondays:
eval $(thefuck --alias FUCK)
2015-04-30 19:43:08 +01:00
```
2015-07-20 19:27:19 +01:00
[Or in your shell config (Bash, Zsh, Fish, Powershell, tcsh).](https://github.com/nvbn/thefuck/wiki/Shell-aliases)
Changes are only available in a new shell session. To make changes immediately
available, run `source ~/.bashrc` (or your shell config file like `.zshrc`).
2015-04-18 21:58:53 +01:00
To run fixed commands without confirmation, use the `--yeah` option (or just `-y` for short, or `--hard` if you're especially frustrated):
```bash
fuck --yeah
```
To fix commands recursively until succeeding, use the `-r` option:
```bash
fuck -r
```
2021-03-13 11:47:55 +00:00
##### [Back to Contents](#contents)
## Updating
```bash
pip3 install thefuck --upgrade
```
**Note: Alias functionality was changed in v1.34 of *The Fuck***
2015-07-20 12:40:07 +01:00
## Uninstall
To remove *The Fuck*, reverse the installation process:
- erase or comment *thefuck* alias line from your Bash, Zsh, Fish, Powershell, tcsh, ... shell config
- use your package manager (brew, pip3, pkg, crew, pip) to uninstall the binaries
2015-04-17 20:51:13 +01:00
## 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:
2015-04-17 20:51:13 +01:00
* `adb_unknown_command` &ndash; fixes misspelled commands like `adb logcta`;
* `ag_literal` &ndash; adds `-Q` to `ag` when suggested;
* `aws_cli` &ndash; fixes misspelled commands like `aws dynamdb scan`;
* `az_cli` &ndash; fixes misspelled commands like `az providers`;
2015-06-06 16:06:10 +01:00
* `cargo` &ndash; runs `cargo build` instead of `cargo`;
* `cargo_no_command` &ndash; fixes wrongs commands like `cargo buid`;
* `cat_dir` &ndash; replaces `cat` with `ls` when you try to `cat` a directory;
2015-05-20 00:50:08 +01:00
* `cd_correction` &ndash; spellchecks and correct failed cd commands;
* `cd_cs` &ndash; changes `cs` to `cd`;
* `cd_mkdir` &ndash; creates directories before cd'ing into them;
2015-05-20 00:50:08 +01:00
* `cd_parent` &ndash; changes `cd..` to `cd ..`;
2016-04-11 14:13:41 +01:00
* `chmod_x` &ndash; add execution bit;
* `choco_install` &ndash; append common suffixes for chocolatey packages;
2015-05-20 00:50:08 +01:00
* `composer_not_command` &ndash; fixes composer command name;
* `conda_mistype` &ndash; fixes conda commands;
* `cp_create_destination` &ndash; creates a new directory when you attempt to `cp` or `mv` to a non existent one
2015-04-21 04:34:34 +01:00
* `cp_omitting_directory` &ndash; adds `-a` when you `cp` directory;
2015-07-20 12:06:57 +01:00
* `cpp11` &ndash; adds missing `-std=c++11` to `g++` or `clang++`;
2015-07-25 22:14:10 +01:00
* `dirty_untar` &ndash; fixes `tar x` command that untarred in the current directory;
* `dirty_unzip` &ndash; fixes `unzip` command that unzipped in the current directory;
* `django_south_ghost` &ndash; adds `--delete-ghost-migrations` to failed because ghosts django south migration;
* `django_south_merge` &ndash; adds `--merge` to inconsistent django south migration;
* `docker_login` &ndash; executes a `docker login` and repeats the previous command;
2015-07-23 22:12:29 +01:00
* `docker_not_command` &ndash; fixes wrong docker commands like `docker tags`;
* `docker_image_being_used_by_container` &dash; removes the container that is using the image before removing the image;
2015-07-22 22:16:12 +01:00
* `dry` &ndash; fixes repetitions like `git git push`;
2016-08-13 14:10:12 +01:00
* `fab_command_not_found` &ndash; fix misspelled fabric commands;
* `fix_alt_space` &ndash; replaces Alt+Space with Space character;
2015-07-29 15:05:46 +01:00
* `fix_file` &ndash; opens a file with an error in your `$EDITOR`;
2017-01-15 14:11:34 +00:00
* `gem_unknown_command` &ndash; fixes wrong `gem` commands;
2016-03-18 02:25:03 +00:00
* `git_add` &ndash; fixes *"pathspec 'foo' did not match any file(s) known to git."*;
* `git_add_force` &ndash; adds `--force` to `git add <pathspec>...` when paths are .gitignore'd;
2016-09-27 23:42:01 +01:00
* `git_bisect_usage` &ndash; fixes `git bisect strt`, `git bisect goood`, `git bisect rset`, etc. when bisecting;
2015-07-19 19:53:08 +01:00
* `git_branch_delete` &ndash; changes `git branch -d` to `git branch -D`;
* `git_branch_delete_checked_out` &ndash; changes `git branch -d` to `git checkout master && git branch -D` when trying to delete a checked out branch;
* `git_branch_exists` &ndash; offers `git branch -d foo`, `git branch -D foo` or `git checkout foo` when creating a branch that already exists;
2015-06-02 04:09:45 +01:00
* `git_branch_list` &ndash; catches `git branch list` in place of `git branch` and removes created branch;
* `git_checkout` &ndash; fixes branch name or creates new branch;
* `git_clone_git_clone` &ndash; replaces `git clone git clone ...` with `git clone ...`
* `git_commit_amend` &ndash; offers `git commit --amend` after previous commit;
* `git_commit_reset` &ndash; offers `git reset HEAD~` after previous commit;
* `git_diff_no_index` &ndash; adds `--no-index` to previous `git diff` on untracked files;
* `git_diff_staged` &ndash; adds `--staged` to previous `git diff` with unexpected output;
2015-07-22 22:16:12 +01:00
* `git_fix_stash` &ndash; fixes `git stash` commands (misspelled subcommand and missing `save`);
* `git_flag_after_filename` &ndash; fixes `fatal: bad flag '...' after filename`
2016-03-12 21:51:47 +00:00
* `git_help_aliased` &ndash; fixes `git help <alias>` commands replacing <alias> with the aliased command;
* `git_hook_bypass` &ndash; adds `--no-verify` flag previous to `git am`, `git commit`, or `git push` command;
* `git_lfs_mistype` &ndash; fixes mistyped `git lfs <command>` commands;
* `git_merge` &ndash; adds remote to branch names;
* `git_merge_unrelated` &ndash; adds `--allow-unrelated-histories` when required
2015-07-22 02:44:37 +01:00
* `git_not_command` &ndash; fixes wrong git commands like `git brnch`;
2015-05-20 00:40:36 +01:00
* `git_pull` &ndash; sets upstream before executing previous `git pull`;
2015-07-20 17:47:59 +01:00
* `git_pull_clone` &ndash; clones instead of pulling when the repo does not exist;
* `git_pull_uncommitted_changes` &ndash; stashes changes before pulling and pops them afterwards;
2015-05-20 00:50:08 +01:00
* `git_push` &ndash; adds `--set-upstream origin $branch` to previous failed `git push`;
* `git_push_different_branch_names` &ndash; fixes pushes when local branch name does not match remote branch name;
2015-07-20 18:51:18 +01:00
* `git_push_pull` &ndash; runs `git pull` when `push` was rejected;
* `git_push_without_commits` &ndash; Creates an initial commit if you forget and only `git add .`, when setting up a new project;
2016-06-23 13:28:37 +01:00
* `git_rebase_no_changes` &ndash; runs `git rebase --skip` instead of `git rebase --continue` when there are no changes;
* `git_remote_delete` &ndash; replaces `git remote delete remote_name` with `git remote remove remote_name`;
* `git_rm_local_modifications` &ndash; adds `-f` or `--cached` when you try to `rm` a locally modified file;
2016-03-14 21:59:32 +00:00
* `git_rm_recursive` &ndash; adds `-r` when you try to `rm` a directory;
* `git_rm_staged` &ndash; adds `-f` or `--cached` when you try to `rm` a file with staged changes
2016-10-30 22:07:14 +00:00
* `git_rebase_merge_dir` &ndash; offers `git rebase (--continue | --abort | --skip)` or removing the `.git/rebase-merge` dir when a rebase is in progress;
* `git_remote_seturl_add` &ndash; runs `git remote add` when `git remote set_url` on nonexistent remote;
* `git_stash` &ndash; stashes your local modifications before rebasing or switching branch;
* `git_stash_pop` &ndash; adds your local modifications before popping stash, then resets;
* `git_tag_force` &ndash; adds `--force` to `git tag <tagname>` when the tag already exists;
2015-10-17 21:35:39 +01:00
* `git_two_dashes` &ndash; adds a missing dash to commands like `git commit -amend` or `git rebase -continue`;
2016-02-08 08:04:19 +00:00
* `go_run` &ndash; appends `.go` extension when compiling/running Go programs;
* `go_unknown_command` &ndash; fixes wrong `go` commands, for example `go bulid`;
2016-08-13 18:31:33 +01:00
* `gradle_no_task` &ndash; fixes not found or ambiguous `gradle` task;
2016-08-13 17:30:46 +01:00
* `gradle_wrapper` &ndash; replaces `gradle` with `./gradlew`;
* `grep_arguments_order` &ndash; fixes `grep` arguments order for situations like `grep -lir . test`;
2018-05-13 14:28:39 +01:00
* `grep_recursive` &ndash; adds `-r` when you try to `grep` directory;
2016-08-13 19:13:05 +01:00
* `grunt_task_not_found` &ndash; fixes misspelled `grunt` commands;
2015-09-01 16:48:55 +01:00
* `gulp_not_task` &ndash; fixes misspelled `gulp` tasks;
2015-04-21 04:34:34 +01:00
* `has_exists_script` &ndash; prepends `./` when script/binary exists;
* `heroku_multiple_apps` &ndash; add `--app <app>` to `heroku` commands like `heroku pg`;
* `heroku_not_command` &ndash; fixes wrong `heroku` commands like `heroku log`;
* `history` &ndash; tries to replace command with the most similar command from history;
2017-02-05 09:28:36 +00:00
* `hostscli` &ndash; tries to fix `hostscli` usage;
* `ifconfig_device_not_found` &ndash; fixes wrong device names like `wlan0` to `wlp2s0`;
2015-06-26 11:00:16 +01:00
* `java` &ndash; removes `.java` extension when running Java programs;
* `javac` &ndash; appends missing `.java` when compiling Java files;
2015-04-21 04:34:34 +01:00
* `lein_not_task` &ndash; fixes wrong `lein` tasks like `lein rpl`;
* `long_form_help` &ndash; changes `-h` to `--help` when the short form version is not supported
2016-03-02 16:48:20 +00:00
* `ln_no_hard_link` &ndash; catches hard link creation on directories, suggest symbolic link;
2016-06-28 01:00:00 +01:00
* `ln_s_order` &ndash; fixes `ln -s` arguments order;
* `ls_all` &ndash; adds `-A` to `ls` when output is empty;
2015-07-22 22:16:12 +01:00
* `ls_lah` &ndash; adds `-lah` to `ls`;
2015-07-20 12:06:57 +01:00
* `man` &ndash; changes manual section;
2015-05-20 00:50:08 +01:00
* `man_no_space` &ndash; fixes man commands without spaces, for example `mandiff`;
* `mercurial` &ndash; fixes wrong `hg` commands;
* `missing_space_before_subcommand` &ndash; fixes command with missing space like `npminstall`;
* `mkdir_p` &ndash; adds `-p` when you try to create a directory without a parent;
2015-08-26 14:01:36 +01:00
* `mvn_no_command` &ndash; adds `clean package` to `mvn`;
* `mvn_unknown_lifecycle_phase` &ndash; fixes misspelled life cycle phases with `mvn`;
2016-08-13 16:28:45 +01:00
* `npm_missing_script` &ndash; fixes `npm` custom script name in `npm run-script <script>`;
2016-08-13 15:38:40 +01:00
* `npm_run_script` &ndash; adds missing `run-script` for custom `npm` scripts;
2016-02-06 12:18:44 +00:00
* `npm_wrong_command` &ndash; fixes wrong npm commands like `npm urgrade`;
2015-04-17 20:51:13 +01:00
* `no_command` &ndash; fixes wrong console commands, for example `vom/vim`;
2015-05-15 17:03:17 +01:00
* `no_such_file` &ndash; creates missing directories with `mv` and `cp` commands;
* `omnienv_no_such_command` &ndash; fixes wrong commands for `goenv`, `nodenv`, `pyenv` and `rbenv` (eg.: `pyenv isntall` or `goenv list`);
* `open` &ndash; either prepends `http://` to address passed to `open` or create a new file or directory and passes it to `open`;
* `pip_install` &ndash; fixes permission issues with `pip install` commands by adding `--user` or prepending `sudo` if necessary;
2015-07-22 22:16:12 +01:00
* `pip_unknown_command` &ndash; fixes wrong `pip` commands, for example `pip instatl/pip install`;
* `php_s` &ndash; replaces `-s` by `-S` when trying to run a local php server;
2016-08-14 04:59:26 +01:00
* `port_already_in_use` &ndash; kills process that bound port;
2017-10-15 14:51:09 +01:00
* `prove_recursively` &ndash; adds `-r` when called with directory;
2018-05-13 14:28:39 +01:00
* `python_command` &ndash; prepends `python` when you try to run non-executable/without `./` python script;
* `python_execute` &ndash; appends missing `.py` when executing Python files;
* `python_module_error` &ndash; fixes ModuleNotFoundError by trying to `pip install` that module;
2015-09-01 16:48:55 +01:00
* `quotation_marks` &ndash; fixes uneven usage of `'` and `"` when containing args';
* `path_from_history` &ndash; replaces not found path with a similar absolute path from history;
* `react_native_command_unrecognized` &ndash; fixes unrecognized `react-native` commands;
* `remove_shell_prompt_literal` &ndash; remove leading shell prompt symbol `$`, common when copying commands from documentations;
* `remove_trailing_cedilla` &ndash; remove trailing cedillas `ç`, a common typo for European keyboard layouts;
2018-05-13 14:28:39 +01:00
* `rm_dir` &ndash; adds `-rf` when you try to remove a directory;
2017-01-15 13:40:50 +00:00
* `scm_correction` &ndash; corrects wrong scm like `hg log` to `git log`;
2015-07-09 17:35:33 +01:00
* `sed_unterminated_s` &ndash; adds missing '/' to `sed`'s `s` commands;
2015-05-20 00:50:08 +01:00
* `sl_ls` &ndash; changes `sl` to `ls`;
2015-04-22 15:52:09 +01:00
* `ssh_known_hosts` &ndash; removes host from `known_hosts` on warning;
* `sudo` &ndash; prepends `sudo` to the previous command if it failed because of permissions;
* `sudo_command_from_user_path` &ndash; runs commands from users `$PATH` with `sudo`;
* `switch_lang` &ndash; switches command from your local layout to en;
2015-07-22 22:16:12 +01:00
* `systemctl` &ndash; correctly orders parameters of confusing `systemctl`;
* `terraform_init.py` &ndash; run `terraform init` before plan or apply;
2015-07-04 13:17:33 +01:00
* `test.py` &ndash; runs `py.test` instead of `test.py`;
2015-09-09 08:53:56 +01:00
* `touch` &ndash; creates missing directories before "touching";
* `tsuru_login` &ndash; runs `tsuru login` if not authenticated or session expired;
* `tsuru_not_command` &ndash; fixes wrong `tsuru` commands like `tsuru shell`;
2015-07-22 22:16:12 +01:00
* `tmux` &ndash; fixes `tmux` commands;
2015-09-01 16:48:55 +01:00
* `unknown_command` &ndash; fixes hadoop hdfs-style "unknown command", for example adds missing '-' to the command on `hdfs dfs ls`;
* `unsudo` &ndash; removes `sudo` from previous command if a process refuses to run on superuser privilege.
* `vagrant_up` &ndash; starts up the vagrant instance;
2016-08-13 18:55:00 +01:00
* `whois` &ndash; fixes `whois` command;
* `workon_doesnt_exists` &ndash; fixes `virtualenvwrapper` env name os suggests to create new.
* `yarn_alias` &ndash; fixes aliased `yarn` commands like `yarn ls`;
* `yarn_command_not_found` &ndash; fixes misspelled `yarn` commands;
* `yarn_command_replaced` &ndash; fixes replaced `yarn` commands;
* `yarn_help` &ndash; makes it easier to open `yarn` documentation;
2015-05-20 00:50:08 +01:00
2021-03-13 11:47:55 +00:00
##### [Back to Contents](#contents)
The following rules are enabled by default on specific platforms only:
2015-05-20 00:50:08 +01:00
* `apt_get` &ndash; installs app from apt if it not installed (requires `python-commandnotfound` / `python3-commandnotfound`);
2015-09-01 16:48:55 +01:00
* `apt_get_search` &ndash; changes trying to search using `apt-get` with searching using `apt-cache`;
2016-01-13 18:53:11 +00:00
* `apt_invalid_operation` &ndash; fixes invalid `apt` and `apt-get` calls, like `apt-get isntall vim`;
* `apt_list_upgradable` &ndash; helps you run `apt list --upgradable` after `apt update`;
* `apt_upgrade` &ndash; helps you run `apt upgrade` after `apt list --upgradable`;
2017-10-15 15:11:08 +01:00
* `brew_cask_dependency` &ndash; installs cask dependencies;
2015-05-01 03:46:58 +01:00
* `brew_install` &ndash; fixes formula name for `brew install`;
* `brew_reinstall` &ndash; turns `brew install <formula>` into `brew reinstall <formula>`;
* `brew_link` &ndash; adds `--overwrite --dry-run` if linking fails;
* `brew_uninstall` &ndash; adds `--force` to `brew uninstall` if multiple versions were installed;
2015-05-20 00:50:08 +01:00
* `brew_unknown_command` &ndash; fixes wrong brew commands, for example `brew docto/brew doctor`;
* `brew_update_formula` &ndash; turns `brew update <formula>` into `brew upgrade <formula>`;
2017-10-06 16:13:29 +01:00
* `dnf_no_such_command` &ndash; fixes mistyped DNF commands;
* `nixos_cmd_not_found` &ndash; installs apps on NixOS;
* `pacman` &ndash; installs app with `pacman` if it is not installed (uses `yay` or `yaourt` if available);
* `pacman_invalid_option` &ndash; replaces lowercase `pacman` options with uppercase.
* `pacman_not_found` &ndash; fixes package name with `pacman`, `yay` or `yaourt`.
* `yum_invalid_operation` &ndash; fixes invalid `yum` calls, like `yum isntall vim`;
2015-04-17 20:51:13 +01:00
The following commands are bundled with *The Fuck*, but are not enabled by
default:
* `git_push_force` &ndash; adds `--force-with-lease` to a `git push` (may conflict with `git_push_pull`);
* `rm_root` &ndash; adds `--no-preserve-root` to `rm -rf /` command.
2021-03-13 11:47:55 +00:00
##### [Back to Contents](#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:
2015-07-27 21:23:26 +01:00
2015-07-20 20:08:46 +01:00
```python
match(command: Command) -> bool
get_new_command(command: Command) -> str | list[str]
2015-07-20 20:08:46 +01:00
```
Additionally, rules can contain optional functions:
2015-08-19 10:00:09 +01:00
```python
side_effect(old_command: Command, fixed_command: str) -> None
2015-08-19 10:00:09 +01:00
```
Rules can also contain the optional variables `enabled_by_default`, `requires_output` and `priority`.
2017-08-31 16:59:38 +01:00
`Command` has three attributes: `script`, `output` and `script_parts`.
Your rule should not change `Command`.
**Rules api changed in 3.0:** To access a rule's settings, import it with
`from thefuck.conf import settings`
2019-10-08 22:47:04 +01:00
`settings` is a special object assembled from `~/.config/thefuck/settings.py`,
and values from env ([see more below](#settings)).
A simple example rule for running a script with `sudo`:
```python
2015-09-07 17:13:17 +01:00
def match(command):
2017-08-31 16:59:38 +01:00
return ('permission denied' in command.output.lower()
or 'EACCES' in command.output)
2015-09-07 17:13:17 +01:00
def get_new_command(command):
return 'sudo {}'.format(command.script)
2015-05-07 19:46:50 +01:00
2015-05-01 03:43:55 +01:00
# Optional:
enabled_by_default = True
2015-09-07 17:13:17 +01:00
def side_effect(command, fixed_command):
2015-05-01 03:43:55 +01:00
subprocess.call('chmod 777 .', shell=True)
2015-05-07 19:46:50 +01:00
priority = 1000 # Lower first, default is 1000
2015-07-27 15:39:52 +01:00
requires_output = True
```
[More examples of rules](https://github.com/nvbn/thefuck/tree/master/thefuck/rules),
[utility functions for rules](https://github.com/nvbn/thefuck/tree/master/thefuck/utils.py),
[app/os-specific helpers](https://github.com/nvbn/thefuck/tree/master/thefuck/specific/).
2021-03-13 11:47:55 +00:00
##### [Back to Contents](#contents)
## Settings
Several *The Fuck* parameters can be changed in the file `$XDG_CONFIG_HOME/thefuck/settings.py`
(`$XDG_CONFIG_HOME` defaults to `~/.config`):
* `rules` &ndash; list of enabled rules, by default `thefuck.const.DEFAULT_RULES`;
* `exclude_rules` &ndash; list of disabled rules, by default `[]`;
2015-07-19 19:53:08 +01:00
* `require_confirmation` &ndash; requires confirmation before running new command, by default `True`;
* `wait_command` &ndash; the max amount of time in seconds for getting previous command output;
* `no_colors` &ndash; disable colored output;
2015-07-15 05:47:54 +01:00
* `priority` &ndash; dict with rules priorities, rule with lower `priority` will be matched first;
2015-10-30 08:23:19 +00:00
* `debug` &ndash; enables debug output, by default `False`;
* `history_limit` &ndash; the numeric value of how many history commands will be scanned, like `2000`;
* `alter_history` &ndash; push fixed command to history, by default `True`;
* `wait_slow_command` &ndash; max amount of time in seconds for getting previous command output if it in `slow_commands` list;
* `slow_commands` &ndash; list of slow commands;
* `num_close_matches` &ndash; the maximum number of close matches to suggest, by default `3`.
* `excluded_search_path_prefixes` &ndash; path prefixes to ignore when searching for commands, by default `[]`.
An example of `settings.py`:
2015-04-29 03:47:15 +01:00
```python
rules = ['sudo', 'no_command']
exclude_rules = ['git_push']
2015-04-29 03:47:15 +01:00
require_confirmation = True
wait_command = 10
no_colors = False
priority = {'sudo': 100, 'no_command': 9999}
2015-07-15 05:47:54 +01:00
debug = False
history_limit = 9999
wait_slow_command = 20
slow_commands = ['react-native', 'gradle']
num_close_matches = 5
2015-04-29 03:47:15 +01:00
```
Or via environment variables:
2015-04-22 21:37:11 +01:00
* `THEFUCK_RULES` &ndash; list of enabled rules, like `DEFAULT_RULES:rm_root` or `sudo:no_command`;
2016-03-24 01:47:09 +00:00
* `THEFUCK_EXCLUDE_RULES` &ndash; list of disabled rules, like `git_pull:git_push`;
* `THEFUCK_REQUIRE_CONFIRMATION` &ndash; require confirmation before running new command, `true/false`;
* `THEFUCK_WAIT_COMMAND` &ndash; the max amount of time in seconds for getting previous command output;
* `THEFUCK_NO_COLORS` &ndash; disable colored output, `true/false`;
* `THEFUCK_PRIORITY` &ndash; priority of the rules, like `no_command=9999:apt_get=100`,
2015-07-15 05:47:54 +01:00
rule with lower `priority` will be matched first;
* `THEFUCK_DEBUG` &ndash; enables debug output, `true/false`;
* `THEFUCK_HISTORY_LIMIT` &ndash; how many history commands will be scanned, like `2000`;
* `THEFUCK_ALTER_HISTORY` &ndash; push fixed command to history `true/false`;
* `THEFUCK_WAIT_SLOW_COMMAND` &ndash; the max amount of time in seconds for getting previous command output if it in `slow_commands` list;
* `THEFUCK_SLOW_COMMANDS` &ndash; list of slow commands, like `lein:gradle`;
* `THEFUCK_NUM_CLOSE_MATCHES` &ndash; the maximum number of close matches to suggest, like `5`.
* `THEFUCK_EXCLUDED_SEARCH_PATH_PREFIXES` &ndash; path prefixes to ignore when searching for commands, by default `[]`.
2015-04-30 19:43:08 +01:00
2015-04-29 03:47:15 +01:00
For example:
```bash
export THEFUCK_RULES='sudo:no_command'
export THEFUCK_EXCLUDE_RULES='git_pull:git_push'
2015-04-29 03:47:15 +01:00
export THEFUCK_REQUIRE_CONFIRMATION='true'
export THEFUCK_WAIT_COMMAND=10
export THEFUCK_NO_COLORS='false'
export THEFUCK_PRIORITY='no_command=9999:apt_get=100'
2015-10-29 02:14:34 +00:00
export THEFUCK_HISTORY_LIMIT='2000'
export THEFUCK_NUM_CLOSE_MATCHES='5'
2015-04-29 03:47:15 +01:00
```
2021-03-13 11:47:55 +00:00
##### [Back to Contents](#contents)
2017-11-23 19:21:44 +00:00
## Third-party packages with rules
If you'd like to make a specific set of non-public rules, but would still like
to share them with others, create a package named `thefuck_contrib_*` with
the following structure:
2017-11-23 19:21:44 +00:00
```
thefuck_contrib_foo
thefuck_contrib_foo
rules
__init__.py
*third-party rules*
__init__.py
*third-party-utils*
setup.py
```
*The Fuck* will find rules located in the `rules` module.
2017-11-23 19:21:44 +00:00
2021-03-13 11:47:55 +00:00
##### [Back to Contents](#contents)
2017-08-26 12:31:09 +01:00
## Experimental instant mode
The default behavior of *The Fuck* requires time to re-run previous commands.
When in instant mode, *The Fuck* saves time by logging output with [script](https://en.wikipedia.org/wiki/Script_(Unix)),
then reading the log.
2017-08-26 12:31:09 +01:00
2017-08-26 13:39:36 +01:00
[![gif with instant mode][instant-mode-gif-link]][instant-mode-gif-link]
Currently, instant mode only supports Python 3 with bash or zsh. zsh's autocorrect function also needs to be disabled in order for thefuck to work properly.
To enable instant mode, add `--enable-experimental-instant-mode`
to the alias initialization in `.bashrc`, `.bash_profile` or `.zshrc`.
2017-08-26 12:31:09 +01:00
For example:
2017-08-26 12:31:09 +01:00
```bash
eval $(thefuck --alias --enable-experimental-instant-mode)
```
2021-03-13 11:47:55 +00:00
##### [Back to Contents](#contents)
2015-04-08 17:15:49 +01:00
## Developing
See [CONTRIBUTING.md](CONTRIBUTING.md)
2015-07-27 20:23:20 +01:00
2015-04-17 20:51:13 +01:00
## License MIT
Project License can be found [here](LICENSE.md).
2016-04-01 01:48:22 +01:00
2016-04-01 01:58:14 +01:00
[version-badge]: https://img.shields.io/pypi/v/thefuck.svg?label=version
[version-link]: https://pypi.python.org/pypi/thefuck/
2021-03-13 13:24:53 +00:00
[workflow-badge]: https://github.com/nvbn/thefuck/workflows/Tests/badge.svg
[workflow-link]: https://github.com/nvbn/thefuck/actions?query=workflow%3ATests
2016-04-01 01:58:14 +01:00
[coverage-badge]: https://img.shields.io/coveralls/nvbn/thefuck.svg
[coverage-link]: https://coveralls.io/github/nvbn/thefuck
[license-badge]: https://img.shields.io/badge/license-MIT-007EC7.svg
2016-04-01 01:48:22 +01:00
[examples-link]: https://raw.githubusercontent.com/nvbn/thefuck/master/example.gif
2017-08-28 02:39:17 +01:00
[instant-mode-gif-link]: https://raw.githubusercontent.com/nvbn/thefuck/master/example_instant_mode.gif
[homebrew]: https://brew.sh/
[linuxbrew]: https://linuxbrew.sh/
2021-03-13 11:47:55 +00:00
##### [Back to Contents](#contents)