1
0
mirror of https://github.com/nvbn/thefuck.git synced 2025-02-20 20:09:07 +00:00

#326 Add support of sudo with pipes

This commit is contained in:
nvbn 2015-08-11 01:15:05 +03:00
parent 41a0a766ce
commit b29113c229
2 changed files with 10 additions and 3 deletions

View File

@ -21,5 +21,9 @@ def test_not_match():
assert not match(Command(), None)
def test_get_new_command():
assert get_new_command(Command('ls'), None) == 'sudo ls'
@pytest.mark.parametrize('before, after', [
('ls', 'sudo ls'),
('echo a > b', 'sudo sh -c "echo a > b"'),
('echo "a" >> b', 'sudo sh -c "echo \\"a\\" >> b"')])
def test_get_new_command(before, after):
assert get_new_command(Command(before), None) == after

View File

@ -28,4 +28,7 @@ def match(command, settings):
def get_new_command(command, settings):
return u'sudo {}'.format(command.script)
if '>' in command.script:
return u'sudo sh -c "{}"'.format(command.script.replace('"', '\\"'))
else:
return u'sudo {}'.format(command.script)