1
0
mirror of https://github.com/nvbn/thefuck.git synced 2025-01-31 02:01:13 +00:00

Fallback to su if sudo doesn't exist

This commit is contained in:
Brandon Moore 2019-10-31 17:54:59 -04:00
parent 70b414aca2
commit cdb1965c9b
No known key found for this signature in database
GPG Key ID: C7A3DAE4ADF4F8ED

15
thefuck/rules/su.py Normal file
View File

@ -0,0 +1,15 @@
def match(command):
if command.script_parts and '&&' not in command.script_parts and command.script_parts[0] == 'su':
return False
return 'command not found: sudo' in command.output.lower()
def get_new_command(command):
if '&&' in command.script:
return u'su -c "sh -c "{}""'.format(" ".join([part for part in command.script_parts if part != "sudo"]))
elif '>' in command.script:
return u'su -c "sh -c "{}""'.format(command.script.replace('"', '\\"'))
else:
return u'su -c {}'.format(command.script)
priority = 1200