mirror of
https://github.com/xonsh/xonsh.git
synced 2025-03-04 08:24:40 +01:00
command-not-found: look up in PATH instead of using hard-coded location
Motivation: command-not-found is available on a different location under NixOS.
This commit is contained in:
parent
adf528f25b
commit
cfc8764b2c
2 changed files with 33 additions and 3 deletions
23
news/command-not-found.rst
Normal file
23
news/command-not-found.rst
Normal file
|
@ -0,0 +1,23 @@
|
|||
**Added:**
|
||||
|
||||
* <news item>
|
||||
|
||||
**Changed:**
|
||||
|
||||
* <news item>
|
||||
|
||||
**Deprecated:**
|
||||
|
||||
* <news item>
|
||||
|
||||
**Removed:**
|
||||
|
||||
* <news item>
|
||||
|
||||
**Fixed:**
|
||||
|
||||
* command-not-found: now works on non-Debian bansed distributions
|
||||
|
||||
**Security:**
|
||||
|
||||
* <news item>
|
|
@ -830,14 +830,21 @@ def command_not_found(cmd):
|
|||
"""Uses the debian/ubuntu command-not-found utility to suggest packages for a
|
||||
command that cannot currently be found.
|
||||
"""
|
||||
import shutil
|
||||
|
||||
if not ON_LINUX:
|
||||
return ""
|
||||
elif not os.path.isfile("/usr/lib/command-not-found"):
|
||||
|
||||
cnf = shutil.which("command-not-found")
|
||||
if cnf is None:
|
||||
# utility is not on PATH
|
||||
return ""
|
||||
c = "/usr/lib/command-not-found {0}; exit 0"
|
||||
c = "{0} {1}; exit 0"
|
||||
s = subprocess.check_output(
|
||||
c.format(cmd), universal_newlines=True, stderr=subprocess.STDOUT, shell=True
|
||||
c.format(cnf, cmd),
|
||||
universal_newlines=True,
|
||||
stderr=subprocess.STDOUT,
|
||||
shell=True,
|
||||
)
|
||||
s = "\n".join(s.rstrip().splitlines()).strip()
|
||||
return s
|
||||
|
|
Loading…
Add table
Reference in a new issue