mirror of
https://github.com/nvbn/thefuck.git
synced 2025-01-18 20:11:17 +00:00
commit
cb33c912e5
10
README.md
10
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;
|
||||
@ -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`;
|
||||
@ -212,7 +212,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`.
|
||||
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -1,17 +0,0 @@
|
||||
import pytest
|
||||
from thefuck.rules.python_compile import match, get_new_command
|
||||
from tests.utils import Command
|
||||
|
||||
|
||||
@pytest.mark.parametrize('command', [
|
||||
Command(script='python foo'),
|
||||
Command(script='python bar')])
|
||||
def test_match(command):
|
||||
assert match(command, None)
|
||||
|
||||
|
||||
@pytest.mark.parametrize('command, new_command', [
|
||||
(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
|
17
tests/rules/test_python_execute.py
Normal file
17
tests/rules/test_python_execute.py
Normal file
@ -0,0 +1,17 @@
|
||||
import pytest
|
||||
from thefuck.rules.python_execute import match, get_new_command
|
||||
from tests.utils import Command
|
||||
|
||||
|
||||
@pytest.mark.parametrize('command', [
|
||||
Command(script='python foo'),
|
||||
Command(script='python bar')])
|
||||
def test_match(command):
|
||||
assert match(command, None)
|
||||
|
||||
|
||||
@pytest.mark.parametrize('command, new_command', [
|
||||
(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
|
@ -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
|
||||
|
@ -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('<remote>', 'origin')\
|
||||
.replace('<branch>', branch)
|
||||
return u'{} && {}'.format(set_upstream, command.script)
|
||||
return shells.and_(set_upstream, command.script)
|
||||
|
@ -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]
|
||||
|
@ -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'
|
||||
|
@ -1,15 +0,0 @@
|
||||
# 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'))
|
||||
|
||||
def get_new_command(command, settings):
|
||||
return command.script + '.py'
|
14
thefuck/rules/python_execute.py
Normal file
14
thefuck/rules/python_execute.py
Normal file
@ -0,0 +1,14 @@
|
||||
# Appends .py when executing 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'))
|
||||
|
||||
|
||||
def get_new_command(command, settings):
|
||||
return command.script + '.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']
|
||||
|
||||
|
||||
|
@ -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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user