Make no_command work only when apt available
This commit is contained in:
@@ -1,19 +1,23 @@
|
||||
from subprocess import Popen, PIPE
|
||||
import re
|
||||
from thefuck.utils import which
|
||||
|
||||
|
||||
def _get_bin(settings):
|
||||
return getattr(settings, 'command_not_found', '/usr/lib/command-not-found')
|
||||
|
||||
|
||||
def _get_output(command, settings):
|
||||
name = command.script.split(' ')[command.script.startswith('sudo')]
|
||||
check_script = '{} {}'.format(getattr(settings, 'command_not_found',
|
||||
'/usr/lib/command-not-found'),
|
||||
name)
|
||||
check_script = '{} {}'.format(_get_bin(settings), name)
|
||||
result = Popen(check_script, shell=True, stderr=PIPE)
|
||||
return result.stderr.read().decode()
|
||||
|
||||
|
||||
def match(command, settings):
|
||||
output = _get_output(command, settings)
|
||||
return "No command" in output and "from package" in output
|
||||
if which('apt-get') and which(_get_bin(settings)):
|
||||
output = _get_output(command, settings)
|
||||
return "No command" in output and "from package" in output
|
||||
|
||||
|
||||
def get_new_command(command, settings):
|
||||
@@ -0,0 +1,19 @@
|
||||
import os
|
||||
|
||||
|
||||
def which(program):
|
||||
def is_exe(fpath):
|
||||
return os.path.isfile(fpath) and os.access(fpath, os.X_OK)
|
||||
|
||||
fpath, fname = os.path.split(program)
|
||||
if fpath:
|
||||
if is_exe(program):
|
||||
return program
|
||||
else:
|
||||
for path in os.environ["PATH"].split(os.pathsep):
|
||||
path = path.strip('"')
|
||||
exe_file = os.path.join(path, program)
|
||||
if is_exe(exe_file):
|
||||
return exe_file
|
||||
|
||||
return None
|
||||
Reference in New Issue
Block a user