#277 Fix the apt_get rule with sudo

This commit is contained in:
mcarton
2015-08-13 17:44:42 +02:00
parent e9ffe2ea9d
commit 95607557d6
2 changed files with 29 additions and 19 deletions
+19 -16
View File
@@ -1,27 +1,30 @@
from thefuck import shells
from thefuck.utils import sudo_support
from thefuck.utils import memoize
try:
import CommandNotFound
except ImportError:
enabled_by_default = False
@sudo_support
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
@sudo_support
@memoize
def get_package(command):
try:
c = CommandNotFound.CommandNotFound()
cmd = command.split(' ')
pkgs = c.getPackages(cmd[0] if cmd[0] != 'sudo' else cmd[1])
name, _ = pkgs[0]
return name
except IndexError:
# IndexError is thrown when no matching package is found
return None
def match(command, settings):
return 'not found' in command.stderr and get_package(command.script)
def get_new_command(command, settings):
c = CommandNotFound.CommandNotFound()
pkgs = c.getPackages(command.script.split(" ")[0])
name, _ = pkgs[0]
name = get_package(command.script)
formatme = shells.and_('sudo apt-get install {}', '{}')
return formatme.format(name, command.script)