From cdb1965c9b6a7e0b40047e81499228dd332cecf5 Mon Sep 17 00:00:00 2001 From: Brandon Moore Date: Thu, 31 Oct 2019 17:54:59 -0400 Subject: [PATCH] Fallback to su if sudo doesn't exist --- thefuck/rules/su.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 thefuck/rules/su.py diff --git a/thefuck/rules/su.py b/thefuck/rules/su.py new file mode 100644 index 00000000..4233e4ed --- /dev/null +++ b/thefuck/rules/su.py @@ -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