diff --git a/thefuck/rules/docker.py b/thefuck/rules/docker.py new file mode 100644 index 00000000..6694046d --- /dev/null +++ b/thefuck/rules/docker.py @@ -0,0 +1,23 @@ +try: + import CommandNotFound +except ImportError: + enabled_by_default = False + + +def match(command, settings): + if 'not found' in command.stderr: + try: + c = CommandNotFound.CommandNotFound() + pkgs = c.getPackages(command.script.split(" ")[0]) + name, _ = pkgs[0] + return True + except IndexError: + # IndexError is thrown when no matching package is found + return False + + +def get_new_command(command, settings): + c = CommandNotFound.CommandNotFound() + pkgs = c.getPackages(command.script.split(" ")[0]) + name, _ = pkgs[0] + return "sudo docker {} && {}".format(name, command.script)