Fix manpath handling in create_manpage_completions.py #6879
...as well as do some (very!) light cleanup. Currently, `create_manpage_completions.py` does not properly understand/respect the `$MANPATH` variable. One important feature of `$MANPATH` is that an empty component (i.e. the trailing : in `foo:bar:`) expands to the 'default' or 'system' path -- that is to say, the path that would be used if `$MANPATH` was unset. This allows the user to extend the manpath without clobbering it, and has been a feature many Unices have included for years. The current implementation blindly uses the `$MANPATH` variable if it exists, which does not allow for this behaviour -- to expand the variable correctly, an external program must be invoked. Therefore, we first shell out to the 'proper' (read: best guess) external program. If that fails, we can then try to use `$MANPATH` directly/literally. Finally, if both of those are impossible, we can fall back to some common paths from widely used operating systems. Note that the `man.conf` parsing has been removed: this is because while many 'traditional' Unices (BSDs, Solaris, macOS) support this file, only macOS actually ships a file -- most other Unices use a `conf.d`-style layout and supporting that from our Python is impractical and silly at best. On GNU (read: Linux) systems, `mandb` uses `/etc/man_db.conf` with slightly different syntax and sematics. As this code-path has bitrotted (and likely never worked, anyway), just remove it. `create_manpage_completions.py` looks like it has suffered a lot of confusion and bitrot in general over the last few years -- and is overdue for a major refactoring. I am quite interested in tackling this, but I plan to wait until the go-ahead to drop support for Python 2 is given, as a major refactor/rewrite that still supports Python 2 (and thus ignores the ergonomic/API/syntax improvements of Python 3) does not make sense to me. Related: #5657 It would probably be good to revisit `man.fish` once again when a comprehensive refactor happens: hopefully every permutation of `man`/`$MANPATH` could be documented as part of that effort.
The comments tell you where we read this file! For mandoc, typically used on OpenBSD, but also on some linuxen.
Please put it back.
My bad -- didn't realize that codepath was actually reachable since a quick read seemed to indicate it would throw an exception. I've re-implemented the functionality with regex (a lot more readable)... Let me know if this will work for OpenBSD -- I don't have any