Make fish_add_path more transparent#10532
Conversation
fish_add_path can be used either interactively, in the commandline, or in config.fish. That's its greatest strength, it's a very DWIM-style command. One of the compromises that entails, however, is that it can't really be very loud about what it does. If it skips a path, it can't write a warning because it might be used in config.fish. But it *can* if it's used interactively. So we try to detect that case and enable verbose mode automatically. That means if you do ```fish fish_add_path /opt/mytool/bin/mytool ``` it may tell you "Skipping path because it is a file instead of a directory:". The check isn't perfect, it goes through status current-command and isatty, but it should be good for most cases (and be false in config.fish).
One issue with fish_add_path at the moment is that it is sometimes a bit too intransparent. You'll try to add a path, but it won't appear - was that because it wasn't a directory, or because it doesn't exist, or because it was already included? If it isn't usable after, did fish_add_path not add it because of something or did something *else* remove it? So we give more explanations - "skipping this because it's a file", "not setting anything because no paths are left to add", ...
|
I agree this is helpful. |
|
I think this is a good idea, but maybe for different reasons? In particular:
I would like to see this error out regardless if it's being used interactively or in |
Unfortunately that would run into the same problem we had when we errored out setting $PATH with an invalid path - people sync their config to other machines, and then ssh breaks. That's why we removed that, and why fish_add_path currently does not print an error, especially because these things aren't really exceptional - the path you gave isn't usable as a component to $PATH, so we're just not adding it. |
|
The specific case of a path existing but being a file is distinct from the path not existing at all, and I think the odds of the path being a file on one system but a directory on another is relatively unlikely? |
|
The failure mode here is too awkward to print messages in rare cases. Rare messages aren't a good idea because then it's hard to know that there's sometimes a message. I don't want to break things for people who do everything right (just copy your config to a different machine which happens to have a different file structure) in favor of people who did something wrong - try to add a file to $PATH, which is clearly broken (that's just not how $PATH works). By contrast in interactive use there's no breakage, it's only upside. So that's a niche we can work in. For people who aren't hardcore users, I would also assume that they'd be more likely to just run fish_add_path interactively, and even for those that don't I would assume they'd run it interactively before as a test and then add it to a config.fish they might keep in version control. |
|
As I said, I'm not against the feature you propose. I am just questioning if there isn't more we can do. Maybe I am missing something but I just cannot see a reasonable "correct case" you speak of that would involve a path sometimes being a directory on some machines and sometimes being a file on others. The typical Unix hierarchy both by definition and by convention would make it, to my mind, extremely improbable. |
It's not whether it's incorrect or not that these systems differ like that. The systems differ in that way, and then the trigger is something as innocent as scp config.fish user@hostand suddenly |
|
I guess that's a fair enough reason. Thanks. |
Description
fish_add_path has a pretty tricky dual nature:
These two have different needs - scripted use needs it to be as quiet as possible. If a path wasn't added because it's already included, that's probably because it already ran. If a path wasn't added because it's a file, that's probably because it was a directory on another system.
Interactive use, on the other hand, suffers a bit from a lack of feedback - you do something and it either silently returns true or false, without explaining why.
We have "verbose" mode -
fish_add_path -v, but that's something people need to know about, and it currently does not explain enough.So, what this does is:
fish_add_path /fooat your prompt, you'll get messagesThat latter part is a bit naughty - numerous CLI guidelines don't like this. But I do believe it's helpful, and I don't really see an alternative - anything else requires adding a flag to get messages interactively, or adding a flag to suppress them noninteractively.
I see people on the internet fail regularly by trying to add a file instead of the directory it contains:
fish_add_path /opt/bin/texlive # <- should be /opt/bin!and we currently have no warning about this - it will just silently return false. You'll have to run
fish_add_path -v /opt/bin/texliveto get "Skipping path because it is a file instead of a directory".Adding this means they'll get the feedback, which should make their mistake obvious - add the directory. (an alternative for this specific case is to automatically dirname any file, but the lack of information hurts in other cases as well)
TODOs: