-
I'm currently maintaining a fork of https://github.com/ioquatix/chruby-fish and I'm having trouble figuring out what is the correct way to handle the functions that get installed by this package. This package installs functions by default into On my macOS system, it doesn't seem to pick these paths up automatically, but according to what I read in the documentation it should. In order to pick up these scripts, I need to do this: set -U XDG_DATA_DIRS /usr/local/share This feels a bit odd to me. Am I doing the right thing here? |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 8 replies
-
How did you install fish? What is the content of My best bet is that you are using a Apple Silicon machine, where Homebrew will use Regardless of the cause of the problem, you can use |
Beta Was this translation helpful? Give feedback.
-
When XDG_DATA_DIRS is empty, many software will fall back to the default path of the system or package manager, which, depending on your situation, will probably contain When you set this environment variable, other software that relies on it will not work properly. If you only expect fish to work properly and you know that other software does not rely on the environment variable at all, then you can set it that way. Otherwise, you may want to set it to And for files with the same name fish will load only the first one in order, so you have to make sure that the path priority is correct and that fish works properly + other software works properly. |
Beta Was this translation helpful? Give feedback.
-
Yeah I think XDG_DATA_DIRS is the right knob. It's not that much different from PATH. If you have /usr/local/bin to your PATH, adding /usr/loca/share to XDG_DATA_DIRS makes sense.
|
Beta Was this translation helpful? Give feedback.
-
On Sat, Nov 27, 2021 at 05:53:02AM -0800, page-down wrote:
The problem with `XDG_DATA_DIRS` is the dependence of other software on its fallback value when it is empty.
- The software will use its own fallback value when its value is empty, which will ensure that the data that comes with the software is loaded correctly.
- The fallback value of `XDG_DATA_DIRS` is decided by the software or distribution when it is packaged.
I don't think applications or distributions are supposed to come up with random fallback values.
The spec [1] says they "should use /usr/local/share/:/usr/share"
[1]: https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html
- When a user installs different package managers and uses software from both package managers, it is likely that there are multiple locations of data dirs.
- There are environments where the value is empty: for example, macOS does not have this environment variable by default, and in some user environments on Linux systems it is not set.
I guess because a fresh system doesn't have a ~/.local/share ? but as soon as you install something there you might want to add it to XDG_DATA_DIRS.
- The user needs to know all the locations that will be used and set the full path correctly, not just append the additional `fish vendored_conf.d paths` that are needed.
Example:
- The user uses package manager X . `XDG_DATA_DIRS` falls back to `/usr/local/share` by default.
- And also package manager Y, All software in this package manager `XDG_DATA_DIRS` falls back to `/opt/local/share` by default.
- The user installs Software A via X, B via Y.
- The user compiles Software K from source and install into `~/.local` , which provides the fish-related `~/.local/K.app/fish/vendored_completions.d`.
- At this point the user wants to use the K, A, B software normally in macOS (`XDG_DATA_DIRS` is empty by default and relies entirely on fallback values).
- The user cannot simply add `~/.local/K.app/share` to `XDG_DATA_DIRS`, he has to understand the situation and add all the paths: `~/.local/K.app/share:/opt/local/share:/usr/local/share:/usr/share`.
Yes. I don't see the problem here. That's what happens with flatpak on Linux (the variables are automatically added by flatpak's profile scripts).
And when the developer of software K wants to add its path to `XDG_DATA_DIRS` and let the fish load additional files, it can't be done.
applications shouldn't write XDG_DATA_DIRS, only read them. The OS/package manager/user is supposed to set that.
- The software K does not have permission and does not expect to install to the system global, so it can't be installed to `/usr/local/share/fish/vendored_completions.d`.
Shouldn't it rather install to $PREFIX/share/fish/vendored_completions.d where $PREFIX is ~/.local in your example?
Note that there is also "pkgconf fish --variable completionsdir" but that's usually for things that are installed system-wide.
- The software K does not know the paths corresponding to the user's package manager X and Y, so it cannot provide the full paths either.
The current workaround is to provide a single path to `XDG_DATA_DIRS` and then clean up after fish starts, making sure that environment variable is empty (or the original env value) under macOS. So at this point fish loads `~/.local/K.app/share/fish/vendored_completions.d` from K, and also makes sure that A and B are fully functional (fallback to their default paths).
This sounds like you are installing to $XDG_DATA_DIRS[1]. I don't think you should. I believe this variable is purely a runtime configuration variable (e.g. the user has full control over what happens even after everything is compiled & installed).
This issue was recently encountered while working with kitty terminal shell integration.
This problem could be solved if fish provided separate environment variables to load directories. Do you have any better suggestions for this? Thank you.
I don't think I have understood the complete problem yet, so bear with me.
These issues are super tricky, maybe we can simplify it somehow.
|
Beta Was this translation helpful? Give feedback.
How did you install fish? What is the content of
$__fish_data_dir/__fish_build_paths.fish
on your machine? The content of that file is used to load the vendored scripts and functions. If you are using Homebrew it should automatically pick up stuff under Homebrew's prefix.My best bet is that you are using a Apple Silicon machine, where Homebrew will use
/opt/homebrew
as its prefix, and hence stuff under/usr/local
will not be loaded automatically.Regardless of the cause of the problem, you can use
$XDG_DATA_DIRS
. It is there for a reason.