1
0
mirror of https://github.com/nvbn/thefuck.git synced 2025-03-20 09:39:01 +00:00

Update env rule

This commit is contained in:
gkodosis 2020-06-01 22:01:23 +03:00
parent 1ac2325479
commit b83c9d755d

View File

@ -1,34 +1,25 @@
import re import re
from subprocess import PIPE, Popen from subprocess import PIPE, Popen
from thefuck.utils import (for_app, replace_command)
from thefuck.utils import (cache, for_app, replace_argument, replace_command, @for_app('pyenv', 'rbenv', 'goenv', 'nodenv')
which)
COMMON_TYPOS = {
'list': ['versions', 'install --list'],
'remove': ['uninstall'],
}
@for_app('env')
def match(command): def match(command):
return ('env' in command.script and return ('env' in command.script and 'no such command' in command.output)
'command not found' in command.output)
def get_env_commands(): def _get_operations(command):
proc_env = Popen(['env', 'commands'], stdout=PIPE) if 'env' in command.script_parts[0]:
proc_env = Popen([str(command.script_parts[0]), 'commands'], stdout=PIPE)
else:
proc_env = Popen([str(command.script_parts[1]), 'commands'], stdout=PIPE)
return [line.decode('utf-8').strip() for line in proc_env.stdout.readlines()] return [line.decode('utf-8').strip() for line in proc_env.stdout.readlines()]
if which('env'): @for_app('pyenv', 'rbenv', 'goenv', 'nodenv')
get_env_commands = cache(which('env'))(get_env_commands)
@for_app('env')
def get_new_command(command): def get_new_command(command):
broken = re.findall(r"command not found `([^']*)'", command.output)[0] if 'env' in command.script_parts[0]:
matched = [replace_argument(command.script, broken, common_typo) invalid_operation = command.script_parts[1]
for common_typo in COMMON_TYPOS.get(broken, [])] else:
matched.extend(replace_command(command, broken, get_env_commands())) invalid_operation = command.script_parts[0]
return matched
return replace_command(command, invalid_operation, _get_operations(command))