-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding directories to the MANPATH is hard. #2090
Comments
Thanks for the detailed explanation. Maybe we should remove MANPATH from the arrayify-whitelist |
A quick question: I just found out that
works fine as a workaround but if I get rid of the quotes it becomes a noop:
I thought fish was supposed to expand unset variables to the empty string? edit: this workaround is actually broken when MANPATH has length > 1 because it will expand to a space-separated list instead of a colon-separated one. |
See this comment for an explanation of how fish handles unset variables. |
One possible workaround that seems to work is to set MANPATH to an array of length 1 containing an empty string in the cases when MANPATH is previously unset because when MANPATH always has length >= 1 then doing
|
Annoyingly, MANPATH is platform-dependent - the double-colon trick doesn't work on BSD or OS X. |
I like @hugomg's idea, because it can be applied in-general to the colon-separation whitelist, without making MANPATH a special snowflake. |
For $PATH it's completely unnecessary - we always set that, for CDPATH my instinct is that it's more unusual to add to it, so it would still leave MANPATH as a "relatively special snowflake", especially when considering all other variables. Plus, if I understand @zanchey's comment correctly, an empty element in our listified MANPATH doesn't actually do the same thing on BSD or OSX as it does on Linux, so this still wouldn't work. The three solutions I can see here
Of those, the second seems like it has the smallest impact. |
While option 2 is least impactful, is MANPATH really special to justify its inclusion in the listify list? |
This is a (slightly reworded) version of what I said in issue #436 where we're talking about how to handle arrays in exported vars in a more general fasion: I'm sorry but I don't see any merit to this complaint. The problem is trivially worked around by explicitly testing whether MANPATH is already set. Which, it seems to me, is something you have to do in any event given the semantics of leading versus trailing versus back to back colons. Having said that I'm inclined to support the proposal to remove MANPATH from the list of special-cased env vars. |
So I've landed here because I'm having trouble adding a path to my MANPATH env var. Could someone post a canonical workaround/technique for appending a path to MANPATH? |
Currently, MANPATH is an array variable, which means that in fish, it can be set like this:
And appended to like this:
This behavior has the issue that there will not be a leading or trailing |
I just do:
and then:
Is this reasonable approach? |
@dpc: No, that is not reasonable. Fish expects every element of $MANPATH to be one directory, what you have done here is set it to one element. If you have a git fish, you'd want (Your approach might work because I don't think we use MANPATH anywhere ourselves, but it is conceptually wrong) |
OK. so I was totally surprised that MANPATH is also an array. After more reading, I am totally confused about fish PATH-like stuff handling. Why would MANPATH be handled by an array, while linker paths etc. are not. IMO, having an array types in the language is beneficent, but trying to force it on PATH/MANPATH/CDPATH (anything else?) is just oddity. Is there any documentation that explains clearly current state of affairs? |
http://fishshell.com/docs/current/index.html#variables-arrays:
This is a whitelist that we hope to never change, to avoid breaking user's scripts. |
@faho: One last question.
Which release was that changed in? |
2.2.0, though I believe it wasn't mentioned in the release notes. This seems like an oversight. |
@faho In the example:
Don't I need to quote "$HOME/opt/share/man" in case $HOME contains a space? |
@dpc: No. Fish does not split variables after they have been set, so anything that is one element in a variable will be passed as one argument. (Not doing this is possibly the single worst design mistake in classic POSIX shell) You can Anyway, this is way out of the scope of this issue. If you have any more questions, feel free to open another one! |
FYI, I have a proof of concept implementation for "tied" variables. This will make it possible to treat |
I'm going to close this as a dup of #4154 since we're definitely going to have tied vars in fish 3.0 and that will solve this issue. |
You should really have gone with hugomg's suggestion to set the default Looking forward to fix in 3.0. |
I took a look at the MANPATH issue described in #2090. The scenario is to append to manpath such that it continues using system paths. In bash one would write this as A "tied variables" approach would allow us to have e.g. My proposal here doesn't make the MANPATH situation better or worse; I think the thing to do is punt and just have an easy story for appending to MANPATH, which is this:
That is not too painful to paste into config.fish. |
With
did you mean
|
@bolry: Fish 3.0 supports both. |
I'm still having an issue with an installer setting manpath in a way that breaks my man command so it no longer will search in the default directories. In my case it is opam, so my man command only finds ocaml related searches. I tried the fixing it with the code snippet above:
but that doesn't seem to work for me. Any updates on this? UPDATE: I fixed if by using |
@evanhackett fyi here is some discussion on the ocaml GitHub about how to handle fish shell: |
This adds the manual page path for the git-subrepo man page when using the fish startup script for git subrepo. This is a not uncontentious issue it seems, in fish shell, see: fish-shell/fish-shell#2090 This however seems to be the suggested solution, and appears to work well, with the man page working along with system manpages, and `manpage` command producing a reasonable result.
This adds the manual page path for the git-subrepo man page when using the fish startup script for git subrepo. This is a not uncontentious issue it seems, in fish shell, see: fish-shell/fish-shell#2090 This however seems to be the suggested solution, and appears to work well, with the man page working along with system manpages, and `manpage` command producing a reasonable result.
This adds the manual page path for the git-subrepo man page when using the fish startup script for git subrepo. This is a not uncontentious issue it seems, in fish shell, see: fish-shell/fish-shell#2090 This however seems to be the suggested solution, and appears to work well, with the man page working along with system manpages, and `manpage` command producing a reasonable result.
Fish treats the MANPATH environment specially and expands it into an array. This unfortunately makes it very easy to mess up the MANPATH and make all system manpages stop working.
The way MANPATH works is that like this:
man
will search for man pages in some default system directories, as specified in /etc/manpath.config)man
searches for manual pages in those directories and DOES NOT search in the default system directoriesIf you want to put some custom directories in the MANPATH while still having
man
use the system manpages then you must make sure that MANPATH either starts or ends with a colon or has a::
in the middle. Fromman manpath
:Now lets go back to Fish. Right now, the first thing that comes to mind if you want to add a directory to the MANPATH is to append it to the end of the array
But this will not have the desired result if MANPATH was not previously set! After running this command
man
will stop displaying the system manpages that it was displaying before. It will only display manpages from the custom directory.In this older issue there are some proposed workarounds but none of them are ideal:
If MANPATH is unset, using these workarounds ensure that MANPATH starts with a colon, which is what we want. But now we will be doing the wrong thing if MANPATH did have a value beforehand! In this case, we will end up with a
::
in the middle of the MANPATH, which also has a special meaning.Is there any big reason for why MANPATH should be an array instead of a regular colon-separated string? Right now Fish makes it easy to iterate over MANPATH or remove paths from the MANPATH but its very hard to just append something to the MANPATH, which I suspect is a much more common thing people will want to do.
The text was updated successfully, but these errors were encountered: