1
0
mirror of https://github.com/nvbn/thefuck.git synced 2025-03-25 12:09:01 +00:00
Aurélien Ooms 2ce1c6bf90 new pattern in sudo rule
`pacman-key --refresh-keys` outputs the following when not run as root

```
==> ERROR: pacman-key needs to be run as root for this operation.
```
2016-01-24 14:38:13 +01:00

42 lines
1.5 KiB
Python

patterns = ['permission denied',
'EACCES',
'pkg: Insufficient privileges',
'you cannot perform this operation unless you are root',
'non-root users cannot',
'Operation not permitted',
'root privilege',
'This command has to be run under the root user.',
'This operation requires root.',
'requested operation requires superuser privilege',
'must be run as root',
'must run as root',
'must be superuser',
'must be root',
'need to be root',
'need root',
'needs to be run as root',
'only root can ',
'You don\'t have access to the history DB.',
'authentication is required',
'eDSPermissionError']
def match(command):
if command.script_parts and '&&' not in command.script_parts and command.script_parts[0] == 'sudo':
return False
for pattern in patterns:
if pattern.lower() in command.stderr.lower()\
or pattern.lower() in command.stdout.lower():
return True
return False
def get_new_command(command):
if '&&' 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('"', '\\"'))
else:
return u'sudo {}'.format(command.script)