diff --git a/thefuck/rules/docker_not_command.py b/thefuck/rules/docker_not_command.py index d8a22cb7..9aa6a220 100644 --- a/thefuck/rules/docker_not_command.py +++ b/thefuck/rules/docker_not_command.py @@ -1,7 +1,7 @@ from itertools import dropwhile, takewhile, islice import re import subprocess -from thefuck.utils import replace_command, for_app +from thefuck.utils import replace_command, for_app, which, cache from thefuck.specific.sudo import sudo_support @@ -20,6 +20,10 @@ def get_docker_commands(): return [line.strip().split(' ')[0] for line in lines] +if which('docker'): + get_docker_commands = cache(which('docker'))(get_docker_commands) + + @sudo_support def get_new_command(command): wrong_command = re.findall( diff --git a/thefuck/rules/gem_unknown_command.py b/thefuck/rules/gem_unknown_command.py index 3d5ee64d..96da2f20 100644 --- a/thefuck/rules/gem_unknown_command.py +++ b/thefuck/rules/gem_unknown_command.py @@ -1,6 +1,6 @@ import re import subprocess -from thefuck.utils import for_app, eager, replace_command +from thefuck.utils import for_app, eager, replace_command, cache, which @for_app('gem') @@ -26,6 +26,10 @@ def _get_all_commands(): yield line.strip().split(' ')[0] +if which('gem'): + _get_all_commands = cache(which('gem'))(_get_all_commands) + + def get_new_command(command): unknown_command = _get_unknown_command(command) all_commands = _get_all_commands() diff --git a/thefuck/rules/grunt_task_not_found.py b/thefuck/rules/grunt_task_not_found.py index 97da5815..49bf0b4f 100644 --- a/thefuck/rules/grunt_task_not_found.py +++ b/thefuck/rules/grunt_task_not_found.py @@ -1,6 +1,6 @@ import re from subprocess import Popen, PIPE -from thefuck.utils import for_app, eager, get_closest +from thefuck.utils import for_app, eager, get_closest, cache regex = re.compile(r'Warning: Task "(.*)" not found.') @@ -10,6 +10,7 @@ def match(command): return regex.findall(command.output) +@cache('Gruntfile.js') @eager def _get_all_tasks(): proc = Popen(['grunt', '--help'], stdout=PIPE) diff --git a/thefuck/rules/gulp_not_task.py b/thefuck/rules/gulp_not_task.py index 812e3973..e0d8589b 100644 --- a/thefuck/rules/gulp_not_task.py +++ b/thefuck/rules/gulp_not_task.py @@ -1,6 +1,6 @@ import re import subprocess -from thefuck.utils import replace_command, for_app +from thefuck.utils import replace_command, for_app, cache @for_app('gulp') @@ -8,6 +8,7 @@ def match(command): return 'is not in your gulpfile' in command.output +@cache('gulpfile.js') def get_gulp_tasks(): proc = subprocess.Popen(['gulp', '--tasks-simple'], stdout=subprocess.PIPE) diff --git a/thefuck/rules/yarn_command_not_found.py b/thefuck/rules/yarn_command_not_found.py index 443257b0..91507754 100644 --- a/thefuck/rules/yarn_command_not_found.py +++ b/thefuck/rules/yarn_command_not_found.py @@ -1,6 +1,7 @@ import re from subprocess import Popen, PIPE -from thefuck.utils import for_app, eager, replace_command, replace_argument +from thefuck.utils import (for_app, eager, replace_command, replace_argument, + cache, which) regex = re.compile(r'error Command "(.*)" not found.') @@ -28,6 +29,10 @@ def _get_all_tasks(): yield line.split(' ')[-1] +if which('yarn'): + _get_all_tasks = cache(which('yarn'))(_get_all_tasks) + + def get_new_command(command): misspelled_task = regex.findall(command.output)[0] if misspelled_task in npm_commands: