From af2bfe7c582c588db7f2a148d46e1cf588938165 Mon Sep 17 00:00:00 2001 From: Namwoo Kim Date: Thu, 23 Apr 2015 15:25:12 +0900 Subject: [PATCH 1/2] Add a support for pip unknown commands --- tests/rules/test_pip_unknown_command.py | 24 ++++++++++++++++++++++++ thefuck/rules/pip_unknown_command.py | 15 +++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 tests/rules/test_pip_unknown_command.py create mode 100644 thefuck/rules/pip_unknown_command.py diff --git a/tests/rules/test_pip_unknown_command.py b/tests/rules/test_pip_unknown_command.py new file mode 100644 index 00000000..61b5c997 --- /dev/null +++ b/tests/rules/test_pip_unknown_command.py @@ -0,0 +1,24 @@ +import pytest +from thefuck.types import Command +from thefuck.rules.pip_unknown_command import match, get_new_command + + +@pytest.fixture +def pip_unknown_cmd(): + return '''ERROR: unknown command "instatl" - maybe you meant "install"''' + + +@pytest.fixture +def pip_unknown_cmd_without_recommend(): + return '''ERROR: unknown command "i"''' + + +def test_match(pip_unknown_cmd, pip_unknown_cmd_without_recommend): + assert match(Command('pip instatl', '', pip_unknown_cmd), None) + assert not match(Command('pip i', '', pip_unknown_cmd_without_recommend), + None) + + +def test_get_new_command(pip_unknown_cmd): + assert get_new_command(Command('pip instatl', '', pip_unknown_cmd), None)\ + == 'pip install' diff --git a/thefuck/rules/pip_unknown_command.py b/thefuck/rules/pip_unknown_command.py new file mode 100644 index 00000000..162258e2 --- /dev/null +++ b/thefuck/rules/pip_unknown_command.py @@ -0,0 +1,15 @@ +import re + + +def match(command, settings): + return ('pip' in command.script and + 'unknown command' in command.stderr and + 'maybe you meant' in command.stderr) + + +def get_new_command(command, settings): + broken_cmd = re.findall(r'ERROR: unknown command \"([a-z]+)\"', + command.stderr)[0] + new_cmd = re.findall(r'maybe you meant \"([a-z]+)\"', command.stderr)[0] + + return command.script.replace(broken_cmd, new_cmd, 1) From bb42780ca5977e7eba7b21dd4a85491695d3d11a Mon Sep 17 00:00:00 2001 From: Namwoo Kim Date: Thu, 23 Apr 2015 15:44:43 +0900 Subject: [PATCH 2/2] Update README.md and remove whitespaces --- README.md | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 6d584ed2..372bafee 100644 --- a/README.md +++ b/README.md @@ -131,12 +131,12 @@ end Or in your Powershell `$PROFILE` on Windows: ```powershell -function fuck { +function fuck { $fuck = $(thefuck (get-history -count 1).commandline) - if($fuck.startswith("echo")) { - $fuck.substring(5) - } - else { iex "$fuck" } + if($fuck.startswith("echo")) { + $fuck.substring(5) + } + else { iex "$fuck" } } ``` @@ -162,6 +162,7 @@ using matched rule and run it. Rules enabled by default: * `lein_not_task` – fixes wrong `lein` tasks like `lein rpl`; * `mkdir_p` – adds `-p` when you trying to create directory without parent; * `no_command` – fixes wrong console commands, for example `vom/vim`; +* `pip_unknown_command` – fixes wrong pip commands, for example `pip instatl/pip install`; * `python_command` – prepends `python` when you trying to run not executable/without `./` python script; * `rm_dir` – adds `-rf` when you trying to remove directory; * `ssh_known_hosts` – removes host from `known_hosts` on warning; @@ -203,7 +204,7 @@ def get_new_command(command, settings): The Fuck has a few settings parameters, they can be changed in `~/.thefuck/settings.py`: * `rules` – list of enabled rules, by default `thefuck.conf.DEFAULT_RULES`; -* `require_confirmation` – require confirmation before running new command, by default `False`; +* `require_confirmation` – require confirmation before running new command, by default `False`; * `wait_command` – max amount of time in seconds for getting previous command output; * `no_colors` – disable colored output.