Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions thefuck/rules/sudo.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
from thefuck.shells import shell

_and_operator = shell.and_('', '').strip()

patterns = ['permission denied',
'eacces',
'pkg: insufficient privileges',
Expand Down Expand Up @@ -29,7 +33,7 @@


def match(command):
if command.script_parts and '&&' not in command.script_parts and command.script_parts[0] == 'sudo':
if command.script_parts and _and_operator not in command.script and command.script_parts[0] == 'sudo':
return False

for pattern in patterns:
Expand All @@ -39,7 +43,7 @@ def match(command):


def get_new_command(command):
if '&&' in command.script:
if _and_operator in command.script:
return u'sudo sh -c "{}"'.format(" ".join([part for part in command.script_parts if part != "sudo"]))
elif '>' in command.script:
return u'sudo sh -c "{}"'.format(command.script.replace('"', '\\"'))
Expand Down