Home

Awesome

Fuckoff

Build Status Coverage MIT License

Fuckoff is a command line utility, forked from nvbn/thefuck. It intends to achieve the same goal as the original project, while being maintained.

Fuckoff corrects errors in your last shell command.

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

Fuckoff currently has no packages. Hopefully this can be changed in the future.

Back to Contents

Setup

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

eval $(fuckoff --alias)
# You can use whatever you want as an alias, like for Mondays:
eval $(fuckoff --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

As with the installation section, there is currently no documentation on this. If you would like to write some, have a read through developing and we would love a PR.

Uninstall

To remove Fuckoff, reverse the installation and setup 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/fuckoff/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 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 fuckoff.conf import settings

settings is a special object assembled from ~/.config/fuckoff/settings.py, and values from env (see more below).

A simple example rule for running a script with sudo:

def match(command):
    return ('permission denied' in command.output.lower()
            or 'EACCES' in command.output)


def get_new_command(command):
    return 'sudo {}'.format(command.script)

# Optional:
enabled_by_default = True

def side_effect(command, fixed_command):
    subprocess.call('chmod 777 .', shell=True)

priority = 1000  # Lower first, default is 1000

requires_output = True

More examples of rules, utility functions for rules, app/os-specific helpers.

Back to Contents

Settings

Several Fuckoff parameters can be changed in the file $XDG_CONFIG_HOME/fuckoff/settings.py ($XDG_CONFIG_HOME defaults to ~/.config):

An example of settings.py:

rules = ['sudo', 'no_command']
exclude_rules = ['git_push']
require_confirmation = True
wait_command = 10
no_colors = False
priority = {'sudo': 100, 'no_command': 9999}
debug = False
history_limit = 9999
wait_slow_command = 20
slow_commands = ['react-native', 'gradle']
num_close_matches = 5

Or via environment variables:

For example:

export FUCKOFF_RULES='sudo:no_command'
export FUCKOFF_EXCLUDE_RULES='git_pull:git_push'
export FUCKOFF_REQUIRE_CONFIRMATION='true'
export FUCKOFF_WAIT_COMMAND=10
export FUCKOFF_NO_COLORS='false'
export FUCKOFF_PRIORITY='no_command=9999:apt_get=100'
export FUCKOFF_HISTORY_LIMIT='2000'
export FUCKOFF_NUM_CLOSE_MATCHES='5'
Back to Contents

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 fuckoff_contrib_* with the following structure:

fuckoff_contrib_foo
  fuckoff_contrib_foo
    rules
      __init__.py
      *third-party rules*
    __init__.py
    *third-party-utils*
  setup.py

Fuckoff will find rules located in the rules module.

Back to Contents

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, then reading the log.

Currently, instant mode only supports Python 3 with bash or zsh. zsh's autocorrect function also needs to be disabled in order for fuckoff to work properly.

To enable instant mode, add --enable-experimental-instant-mode to the alias initialization in .bashrc, .bash_profile or .zshrc.

For example:

eval $(fuckoff --alias --enable-experimental-instant-mode)
Back to Contents

Developing

See [CONTRIBUTING.md]

License MIT

Project License can be found here.

Back to Contents