From e3cc9c52e68805bedde8b04ac2b5608c711b894c Mon Sep 17 00:00:00 2001 From: mcarton Date: Fri, 26 Jun 2015 11:41:55 +0200 Subject: [PATCH 1/7] Remove redundant patterns in sudo rule --- thefuck/rules/sudo.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/thefuck/rules/sudo.py b/thefuck/rules/sudo.py index 70a726cc..1a87ffec 100644 --- a/thefuck/rules/sudo.py +++ b/thefuck/rules/sudo.py @@ -7,14 +7,12 @@ patterns = ['permission denied', 'root privilege', 'This command has to be run under the root user.', 'This operation requires root.', - 'You need to be root to perform this command.', 'requested operation requires superuser privilege', 'must be run as root', 'must be superuser', 'must be root', 'need to be root', 'need root', - 'you must be root to run this program.', 'only root can do that'] From 330f91f5dcde7119bb3f264dc28da36158a3909d Mon Sep 17 00:00:00 2001 From: mcarton Date: Fri, 26 Jun 2015 11:55:10 +0200 Subject: [PATCH 2/7] Cleanup the systemctl rule --- thefuck/rules/systemctl.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/thefuck/rules/systemctl.py b/thefuck/rules/systemctl.py index 6065abc5..9bd791c3 100644 --- a/thefuck/rules/systemctl.py +++ b/thefuck/rules/systemctl.py @@ -1,16 +1,21 @@ """ -The confusion in systemctl's param order is massive +The confusion in systemctl's param order is massive. """ from thefuck.utils import sudo_support + @sudo_support def match(command, settings): - #Catches 'Unknown operation 'service'.' when executing systemctl with misordered arguments + # Catches 'Unknown operation 'service'.' when executing systemctl with + # misordered arguments cmd = command.script.split() - return ('systemctl' in command.script) and ('Unknown operation \'' in command.stderr) and (len(cmd) - cmd.index('systemctl') == 3); + return ('systemctl' in command.script and + 'Unknown operation \'' in command.stderr and + len(cmd) - cmd.index('systemctl') == 3) + @sudo_support def get_new_command(command, settings): cmd = command.script.split() - cmd[len(cmd)-1], cmd[len(cmd)-2] = cmd[len(cmd)-2], cmd[len(cmd)-1] + cmd[-1], cmd[-2] = cmd[-2], cmd[-1] return ' '.join(cmd) From 6d718a38dc930685044441ce42f3f944ed5b215c Mon Sep 17 00:00:00 2001 From: mcarton Date: Fri, 26 Jun 2015 12:00:16 +0200 Subject: [PATCH 3/7] :sort rules in README --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index cfd86e34..4cc8ab39 100644 --- a/README.md +++ b/README.md @@ -154,12 +154,10 @@ using the matched rule and runs it. Rules enabled by default are as follows: * `composer_not_command` – fixes composer command name; * `cp_omitting_directory` – adds `-a` when you `cp` directory; * `cpp11` – add missing `-std=c++11` to `g++` or `clang++`; -* `dry` – fix repetitions like "git git push"; * `django_south_ghost` – adds `--delete-ghost-migrations` to failed because ghosts django south migration; * `django_south_merge` – adds `--merge` to inconsistent django south migration; +* `dry` – fix repetitions like "git git push"; * `fix_alt_space` – replaces Alt+Space with Space character; -* `javac` – appends missing `.java` when compiling Java files; -* `java` – removes `.java` extension when running Java programs; * `git_add` – fix *"Did you forget to 'git add'?"*; * `git_branch_list` – catches `git branch list` in place of `git branch` and removes created branch; * `git_checkout` – creates the branch before checking-out; @@ -171,6 +169,8 @@ using the matched rule and runs it. Rules enabled by default are as follows: * `go_run` – appends `.go` extension when compiling/running Go programs * `grep_recursive` – adds `-r` when you trying to grep directory; * `has_exists_script` – prepends `./` when script/binary exists; +* `java` – removes `.java` extension when running Java programs; +* `javac` – appends missing `.java` when compiling Java files; * `lein_not_task` – fixes wrong `lein` tasks like `lein rpl`; * `ls_lah` – adds -lah to ls; * `man` – change manual section; From b59e83cca9ba2b0566102c507b9da77a66fbfdd9 Mon Sep 17 00:00:00 2001 From: mcarton Date: Fri, 26 Jun 2015 12:02:05 +0200 Subject: [PATCH 4/7] Fix punctuation in README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 4cc8ab39..8e10d027 100644 --- a/README.md +++ b/README.md @@ -211,7 +211,7 @@ in `~/.thefuck/rules`. Rule should contain two functions: and `get_new_command(command: Command, settings: Settings) -> str`. Also the rule can contain optional function `side_effect(command: Command, settings: Settings) -> None` and -optional boolean `enabled_by_default` +optional boolean `enabled_by_default`. `Command` has three attributes: `script`, `stdout` and `stderr`. From 40fe604adc38095a65b2fd9168badb50daa65b14 Mon Sep 17 00:00:00 2001 From: mcarton Date: Fri, 26 Jun 2015 13:58:50 +0200 Subject: [PATCH 5/7] Replace use of '&&' by shells.and_ --- thefuck/rules/git_pull.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/thefuck/rules/git_pull.py b/thefuck/rules/git_pull.py index cee34616..98470b15 100644 --- a/thefuck/rules/git_pull.py +++ b/thefuck/rules/git_pull.py @@ -1,3 +1,6 @@ +from thefuck import shells + + def match(command, settings): return ('git' in command.script and 'pull' in command.script @@ -9,4 +12,4 @@ def get_new_command(command, settings): branch = line.split(' ')[-1] set_upstream = line.replace('', 'origin')\ .replace('', branch) - return u'{} && {}'.format(set_upstream, command.script) + return shells.and_(set_upstream, command.script) From 7173e0dbadafecfb6b45ad6d5020a3fdf03a58f9 Mon Sep 17 00:00:00 2001 From: mcarton Date: Fri, 26 Jun 2015 14:08:25 +0200 Subject: [PATCH 6/7] Use spaces instead of tabs The is more common in python and follows other rules usage. --- tests/rules/test_brew_upgrade.py | 8 ++++---- tests/rules/test_go_run.py | 12 ++++++------ tests/rules/test_java.py | 12 ++++++------ tests/rules/test_javac.py | 12 ++++++------ tests/rules/test_open.py | 28 ++++++++++++++-------------- tests/rules/test_python_compile.py | 12 ++++++------ tests/rules/test_quotation_marks.py | 8 ++++---- thefuck/rules/java.py | 11 ++++++----- thefuck/rules/javac.py | 14 +++++++------- thefuck/rules/python_compile.py | 11 +++++------ 10 files changed, 64 insertions(+), 64 deletions(-) diff --git a/tests/rules/test_brew_upgrade.py b/tests/rules/test_brew_upgrade.py index efe0d4ce..941bb2c3 100644 --- a/tests/rules/test_brew_upgrade.py +++ b/tests/rules/test_brew_upgrade.py @@ -4,12 +4,12 @@ from tests.utils import Command @pytest.mark.parametrize('command', [ - Command(script='brew upgrade')]) + Command(script='brew upgrade')]) def test_match(command): - assert match(command, None) + assert match(command, None) @pytest.mark.parametrize('command, new_command', [ - (Command('brew upgrade'), 'brew upgrade --all')]) + (Command('brew upgrade'), 'brew upgrade --all')]) def test_get_new_command(command, new_command): - assert get_new_command(command, None) == new_command + assert get_new_command(command, None) == new_command diff --git a/tests/rules/test_go_run.py b/tests/rules/test_go_run.py index 05745054..0ab140b4 100644 --- a/tests/rules/test_go_run.py +++ b/tests/rules/test_go_run.py @@ -4,14 +4,14 @@ from tests.utils import Command @pytest.mark.parametrize('command', [ - Command(script='go run foo'), - Command(script='go run bar')]) + Command(script='go run foo'), + Command(script='go run bar')]) def test_match(command): - assert match(command, None) + assert match(command, None) @pytest.mark.parametrize('command, new_command', [ - (Command('go run foo'), 'go run foo.go'), - (Command('go run bar'), 'go run bar.go')]) + (Command('go run foo'), 'go run foo.go'), + (Command('go run bar'), 'go run bar.go')]) def test_get_new_command(command, new_command): - assert get_new_command(command, None) == new_command + assert get_new_command(command, None) == new_command diff --git a/tests/rules/test_java.py b/tests/rules/test_java.py index d51c8806..928ac69d 100644 --- a/tests/rules/test_java.py +++ b/tests/rules/test_java.py @@ -4,14 +4,14 @@ from tests.utils import Command @pytest.mark.parametrize('command', [ - Command(script='java foo.java'), - Command(script='java bar.java')]) + Command(script='java foo.java'), + Command(script='java bar.java')]) def test_match(command): - assert match(command, None) + assert match(command, None) @pytest.mark.parametrize('command, new_command', [ - (Command('java foo.java'), 'java foo'), - (Command('java bar.java'), 'java bar')]) + (Command('java foo.java'), 'java foo'), + (Command('java bar.java'), 'java bar')]) def test_get_new_command(command, new_command): - assert get_new_command(command, None) == new_command + assert get_new_command(command, None) == new_command diff --git a/tests/rules/test_javac.py b/tests/rules/test_javac.py index 6bac2d78..47000384 100644 --- a/tests/rules/test_javac.py +++ b/tests/rules/test_javac.py @@ -4,14 +4,14 @@ from tests.utils import Command @pytest.mark.parametrize('command', [ - Command(script='javac foo'), - Command(script='javac bar')]) + Command(script='javac foo'), + Command(script='javac bar')]) def test_match(command): - assert match(command, None) + assert match(command, None) @pytest.mark.parametrize('command, new_command', [ - (Command('javac foo'), 'javac foo.java'), - (Command('javac bar'), 'javac bar.java')]) + (Command('javac foo'), 'javac foo.java'), + (Command('javac bar'), 'javac bar.java')]) def test_get_new_command(command, new_command): - assert get_new_command(command, None) == new_command + assert get_new_command(command, None) == new_command diff --git a/tests/rules/test_open.py b/tests/rules/test_open.py index ea350b55..892f9b57 100644 --- a/tests/rules/test_open.py +++ b/tests/rules/test_open.py @@ -4,22 +4,22 @@ from tests.utils import Command @pytest.mark.parametrize('command', [ - Command(script='open foo.com'), - Command(script='open foo.ly'), - Command(script='open foo.org'), - Command(script='open foo.net'), - Command(script='open foo.se'), - Command(script='open foo.io')]) + Command(script='open foo.com'), + Command(script='open foo.ly'), + Command(script='open foo.org'), + Command(script='open foo.net'), + Command(script='open foo.se'), + Command(script='open foo.io')]) def test_match(command): - assert match(command, None) + assert match(command, None) @pytest.mark.parametrize('command, new_command', [ - (Command('open foo.com'), 'open http://foo.com'), - (Command('open foo.ly'), 'open http://foo.ly'), - (Command('open foo.org'), 'open http://foo.org'), - (Command('open foo.net'), 'open http://foo.net'), - (Command('open foo.se'), 'open http://foo.se'), - (Command('open foo.io'), 'open http://foo.io')]) + (Command('open foo.com'), 'open http://foo.com'), + (Command('open foo.ly'), 'open http://foo.ly'), + (Command('open foo.org'), 'open http://foo.org'), + (Command('open foo.net'), 'open http://foo.net'), + (Command('open foo.se'), 'open http://foo.se'), + (Command('open foo.io'), 'open http://foo.io')]) def test_get_new_command(command, new_command): - assert get_new_command(command, None) == new_command + assert get_new_command(command, None) == new_command diff --git a/tests/rules/test_python_compile.py b/tests/rules/test_python_compile.py index d7bf9889..c3986503 100644 --- a/tests/rules/test_python_compile.py +++ b/tests/rules/test_python_compile.py @@ -4,14 +4,14 @@ from tests.utils import Command @pytest.mark.parametrize('command', [ - Command(script='python foo'), - Command(script='python bar')]) + Command(script='python foo'), + Command(script='python bar')]) def test_match(command): - assert match(command, None) + assert match(command, None) @pytest.mark.parametrize('command, new_command', [ - (Command('python foo'), 'python foo.py'), - (Command('python bar'), 'python bar.py')]) + (Command('python foo'), 'python foo.py'), + (Command('python bar'), 'python bar.py')]) def test_get_new_command(command, new_command): - assert get_new_command(command, None) == new_command + assert get_new_command(command, None) == new_command diff --git a/tests/rules/test_quotation_marks.py b/tests/rules/test_quotation_marks.py index 2963ac77..7c654e77 100644 --- a/tests/rules/test_quotation_marks.py +++ b/tests/rules/test_quotation_marks.py @@ -4,16 +4,16 @@ from tests.utils import Command @pytest.mark.parametrize('command', [ - Command(script="git commit -m \'My Message\""), + Command(script="git commit -m \'My Message\""), Command(script="git commit -am \"Mismatched Quotation Marks\'"), Command(script="echo \"hello\'")]) def test_match(command): - assert match(command, None) + assert match(command, None) @pytest.mark.parametrize('command, new_command', [ - (Command("git commit -m \'My Message\""), "git commit -m \"My Message\""), + (Command("git commit -m \'My Message\""), "git commit -m \"My Message\""), (Command("git commit -am \"Mismatched Quotation Marks\'"), "git commit -am \"Mismatched Quotation Marks\""), (Command("echo \"hello\'"), "echo \"hello\"")]) def test_get_new_command(command, new_command): - assert get_new_command(command, None) == new_command + assert get_new_command(command, None) == new_command diff --git a/thefuck/rules/java.py b/thefuck/rules/java.py index 31474e80..d2852328 100644 --- a/thefuck/rules/java.py +++ b/thefuck/rules/java.py @@ -1,13 +1,14 @@ # Fixes common java command mistake -# +# # Example: # > java foo.java # Error: Could not find or load main class foo.java -# + def match(command, settings): - return (command.script.startswith ('java ') - and command.script.endswith ('.java')) + return (command.script.startswith('java ') + and command.script.endswith('.java')) + def get_new_command(command, settings): - return command.script[:-5] + return command.script[:-5] diff --git a/thefuck/rules/javac.py b/thefuck/rules/javac.py index 7ee4389f..af19cc71 100644 --- a/thefuck/rules/javac.py +++ b/thefuck/rules/javac.py @@ -1,15 +1,15 @@ # Appends .java when compiling java files -# +# # Example: # > javac foo -# error: Class names, 'foo', are only accepted if annotation +# error: Class names, 'foo', are only accepted if annotation # processing is explicitly requested -# -# + def match(command, settings): - return (command.script.startswith ('javac ') - and not command.script.endswith('.java')) + return (command.script.startswith('javac ') + and not command.script.endswith('.java')) + def get_new_command(command, settings): - return command.script + '.java' + return command.script + '.java' diff --git a/thefuck/rules/python_compile.py b/thefuck/rules/python_compile.py index 39adcafa..1b15aab6 100644 --- a/thefuck/rules/python_compile.py +++ b/thefuck/rules/python_compile.py @@ -1,15 +1,14 @@ # Appends .py when compiling python files -# +# # Example: # > python foo # error: python: can't open file 'foo': [Errno 2] No such file or directory -# -# def match(command, settings): - return (command.script.startswith ('python ') - and not command.script.endswith('.py')) + return (command.script.startswith('python ') + and not command.script.endswith('.py')) + def get_new_command(command, settings): - return command.script + '.py' + return command.script + '.py' From 5552fd3dc9d061dcf841a1c21509e51ec70c058a Mon Sep 17 00:00:00 2001 From: mcarton Date: Fri, 26 Jun 2015 14:37:44 +0200 Subject: [PATCH 7/7] s/compile/execute when talking about Python The word 'compile' is just misleading here. --- README.md | 2 +- tests/rules/{test_python_compile.py => test_python_execute.py} | 2 +- thefuck/rules/{python_compile.py => python_execute.py} | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) rename tests/rules/{test_python_compile.py => test_python_execute.py} (87%) rename thefuck/rules/{python_compile.py => python_execute.py} (88%) diff --git a/README.md b/README.md index 8e10d027..a8a35e1c 100644 --- a/README.md +++ b/README.md @@ -181,7 +181,7 @@ using the matched rule and runs it. Rules enabled by default are as follows: * `open` – prepends `http` to address passed to `open`; * `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; -* `python_compile` – appends missing `.py` when compiling and running Python files; +* `python_execute` – appends missing `.py` when executing Python files; * `quotation_marks` – fixes uneven usage of `'` and `"` when containing args' * `rm_dir` – adds `-rf` when you trying to remove directory; * `sl_ls` – changes `sl` to `ls`; diff --git a/tests/rules/test_python_compile.py b/tests/rules/test_python_execute.py similarity index 87% rename from tests/rules/test_python_compile.py rename to tests/rules/test_python_execute.py index c3986503..168cb59b 100644 --- a/tests/rules/test_python_compile.py +++ b/tests/rules/test_python_execute.py @@ -1,5 +1,5 @@ import pytest -from thefuck.rules.python_compile import match, get_new_command +from thefuck.rules.python_execute import match, get_new_command from tests.utils import Command diff --git a/thefuck/rules/python_compile.py b/thefuck/rules/python_execute.py similarity index 88% rename from thefuck/rules/python_compile.py rename to thefuck/rules/python_execute.py index 1b15aab6..d4d9d266 100644 --- a/thefuck/rules/python_compile.py +++ b/thefuck/rules/python_execute.py @@ -1,4 +1,4 @@ -# Appends .py when compiling python files +# Appends .py when executing python files # # Example: # > python foo