1
0
mirror of https://github.com/nvbn/thefuck.git synced 2025-03-16 07:38:50 +00:00
thefuck/thefuck/rules/chmod_x.py
Alice Jacka 7fe4c309a7
Update chmod_x to work with non-relative paths
Originally this rule only worked for scripts run with relative paths (eg `./funStuff.sh`) but that's not always what we need
Imagine I have a file at `/home/alice/scripts/funStuff.sh` and my cwd is `/home/alice` I could run the script with `./scripts/funStuff.sh` or '~/scripts/funStuff.sh` or `/home/alice/scripts/funStuff.sh`
2024-09-11 23:49:33 +10:00

15 lines
422 B
Python

import os
from thefuck.shells import shell
def match(command):
return ('permission denied' in command.output.lower()
and os.path.exists(os.path.expanduser(command.script_parts[0]))
and not os.access(os.path.expanduser(command.script_parts[0]), os.X_OK))
def get_new_command(command):
return shell.and_(
'chmod +x {}'.format(command.script_parts[0][2:]),
command.script)