mirror of
https://github.com/fish-shell/fish-shell
synced 2024-12-26 21:03:12 +00:00
create_manpage_completions: Try more ways to get manpath
Haiku only has `man --path`. Still doesn't support OpenBSD. Use $MANPATH if available. This needs to: - Ignore stderr (we pipe it and throw it away) - Read the subprocess returncode, since `man --path` is an existing command that fails instead of a non-existent one (that raises an exception) - Properly set up the fallback Fixes #2194.
This commit is contained in:
parent
06282f02fd
commit
03e0f1eb21
1 changed files with 19 additions and 5 deletions
|
@ -857,12 +857,26 @@ def parse_and_output_man_pages(paths, output_directory, show_progress):
|
||||||
def get_paths_from_manpath():
|
def get_paths_from_manpath():
|
||||||
# Return all the paths to man(1) and man(8) files in the manpath
|
# Return all the paths to man(1) and man(8) files in the manpath
|
||||||
import subprocess, os
|
import subprocess, os
|
||||||
proc = subprocess.Popen(['manpath'], stdout=subprocess.PIPE)
|
# $MANPATH takes precedence, just like with `man` on the CLI.
|
||||||
manpath, err_data = proc.communicate()
|
if os.getenv("MANPATH"):
|
||||||
|
manpath = os.getenv("MANPATH")
|
||||||
|
else:
|
||||||
|
# Some systems have manpath, others have `man --path` (like Haiku).
|
||||||
|
# TODO: Deal with systems that have neither (OpenBSD)
|
||||||
|
for prog in [['manpath'], ['man', '--path']]:
|
||||||
|
try:
|
||||||
|
proc = subprocess.Popen(prog, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||||
|
except OSError: # Command does not exist, keep trying
|
||||||
|
continue
|
||||||
|
break # Command exists, use it.
|
||||||
|
manpath, err_data = proc.communicate()
|
||||||
parent_paths = manpath.decode().strip().split(':')
|
parent_paths = manpath.decode().strip().split(':')
|
||||||
if not parent_paths:
|
if not parent_paths or proc.returncode > 0:
|
||||||
sys.stderr.write("Unable to get the manpath (tried manpath)\n")
|
# HACK: Use some fallback in case we can't get anything else.
|
||||||
sys.exit(-1)
|
# `mandoc` does not provide `manpath` or `man --path` and $MANPATH might not be set, so just use the default for mandoc (minus /usr/X11R6/man, because that's not relevant).
|
||||||
|
# The alternative is reading its config file (/etc/man.conf)
|
||||||
|
sys.stderr.write("Unable to get the manpath, falling back to /usr/share/man:/usr/local/share/man. Please set $MANPATH if that is not correct.\n")
|
||||||
|
parent_paths = ["/usr/share/man", "/usr/local/share/man"]
|
||||||
result = []
|
result = []
|
||||||
for parent_path in parent_paths:
|
for parent_path in parent_paths:
|
||||||
for section in ['man1', 'man6', 'man8']:
|
for section in ['man1', 'man6', 'man8']:
|
||||||
|
|
Loading…
Reference in a new issue