mirror of
https://github.com/nvbn/thefuck.git
synced 2025-01-18 20:11:17 +00:00
Added a rule to delete sudo for pacaur. (#787)
This commit is contained in:
parent
b65e3a9aad
commit
dd9554539f
@ -4,7 +4,7 @@ Magnificent app which corrects your previous console command,
|
||||
inspired by a [@liamosaur](https://twitter.com/liamosaur/)
|
||||
[tweet](https://twitter.com/liamosaur/status/506975850596536320).
|
||||
|
||||
The Fuck is too slow? [Try experimental instant mode!](#experimental-instant-mode)
|
||||
The Fuck is too slow? [Try experimental instant mode!](#experimental-instant-mode)
|
||||
|
||||
[![gif with examples][examples-link]][examples-link]
|
||||
|
||||
@ -278,6 +278,7 @@ using the matched rule and runs it. Rules enabled by default are as follows:
|
||||
* `tsuru_not_command` – fixes wrong `tsuru` commands like `tsuru shell`;
|
||||
* `tmux` – fixes `tmux` commands;
|
||||
* `unknown_command` – fixes hadoop hdfs-style "unknown command", for example adds missing '-' to the command on `hdfs dfs ls`;
|
||||
* `unsudo` – removes `sudo` from previous command if a process refuses to run on super user privilege.
|
||||
* `vagrant_up` – starts up the vagrant instance;
|
||||
* `whois` – fixes `whois` command;
|
||||
* `workon_doesnt_exists` – fixes `virtualenvwrapper` env name os suggests to create new.
|
||||
|
22
tests/rules/test_unsudo.py
Normal file
22
tests/rules/test_unsudo.py
Normal file
@ -0,0 +1,22 @@
|
||||
import pytest
|
||||
from thefuck.rules.unsudo import match, get_new_command
|
||||
from thefuck.types import Command
|
||||
|
||||
|
||||
@pytest.mark.parametrize('output', [
|
||||
'you cannot perform this operation as root'])
|
||||
def test_match(output):
|
||||
assert match(Command('sudo ls', output))
|
||||
|
||||
|
||||
def test_not_match():
|
||||
assert not match(Command('', ''))
|
||||
assert not match(Command('sudo ls', 'Permission denied'))
|
||||
assert not match(Command('ls', 'you cannot perform this operation as root'))
|
||||
|
||||
|
||||
@pytest.mark.parametrize('before, after', [
|
||||
('sudo ls', 'ls'),
|
||||
('sudo pacaur -S helloworld', 'pacaur -S helloworld')])
|
||||
def test_get_new_command(before, after):
|
||||
assert get_new_command(Command(before, '')) == after
|
15
thefuck/rules/unsudo.py
Normal file
15
thefuck/rules/unsudo.py
Normal file
@ -0,0 +1,15 @@
|
||||
patterns = ['you cannot perform this operation as root']
|
||||
|
||||
|
||||
def match(command):
|
||||
if command.script_parts and command.script_parts[0] != 'sudo':
|
||||
return False
|
||||
|
||||
for pattern in patterns:
|
||||
if pattern in command.output.lower():
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
def get_new_command(command):
|
||||
return ' '.join(command.script_parts[1:])
|
Loading…
x
Reference in New Issue
Block a user