mirror of
https://github.com/nvbn/thefuck.git
synced 2025-02-20 20:09:07 +00:00
#78 Disable when can't import CommandNotFound
This commit is contained in:
parent
fa465620ba
commit
e554238996
@ -1,28 +1,23 @@
|
||||
import sys
|
||||
try:
|
||||
import CommandNotFound
|
||||
except ImportError:
|
||||
enabled_by_default = False
|
||||
|
||||
|
||||
def match(command, settings):
|
||||
try:
|
||||
import CommandNotFound
|
||||
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
|
||||
except:
|
||||
return False
|
||||
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):
|
||||
try:
|
||||
import CommandNotFound
|
||||
c = CommandNotFound.CommandNotFound()
|
||||
if 'not found' in command.stderr:
|
||||
pkgs = c.getPackages(command.script.split(" ")[0])
|
||||
name,_ = pkgs[0]
|
||||
return "sudo apt-get install %s" % name
|
||||
except:
|
||||
sys.stderr.write("Can't apt fuck\n")
|
||||
return ""
|
||||
c = CommandNotFound.CommandNotFound()
|
||||
pkgs = c.getPackages(command.script.split(" ")[0])
|
||||
name, _ = pkgs[0]
|
||||
return "sudo apt-get install {} && {}".format(name, command.script)
|
||||
|
Loading…
x
Reference in New Issue
Block a user