xdg
xdg copied to clipboard
Add base support for XDG base user executable dir
https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html
There is a single base directory relative to which user-specific executable files may be written.
User-specific executable files may be stored in $HOME/.local/bin.
Please feel free to push to this branch to help complete it. WIP/things to consider at least:
- Support for other OS's besides usual Unixy XDG ones
- Relation to the existing other/non-standard
ApplicationDirs
-
TODO
comments in code
Hi @scop. Thank you for the PR.
I've been thinking of defining an ExecutableHome
directory too. Maybe ExecutableDirs
as well, which would contain the paths in the $PATH
environment variable (maybe adding ~/bin
too if not already there), with sensible defaults. Not sure how useful would that be, but it would mimic the usual pair-like behavior of other XDG base directories (XDG_DATA_HOME
and XDG_DATA_DIRS
), even though there are no standard environment variables for this.
I'm trying to find a suitable equivalent for Windows. I wasn't able to find anything similar among the Windows Known Folders. For Plan 9, ExecutableHome
would probably be $home/bin
. For macOS, it could be ~/.local/bin
although I'm not really sure that's the best practice.
I'd steer clear from adding anything to ExecutableDirs
that aren't dirs from which executables without a path are searched from. They don't work the way it's reasonable to assume they would based on the name. Then again that's something one could say about ~/.local/bin
too -- if it's not in $PATH
, then dropping an executable there doesn't make it available for running without giving a path to it.
But that's actually one use case for ExecutableDirs
: something installing an executable to ExecutableHome
could check that the dir is in ExecutableDirs
and emit a warning if not.
BTW, ISTR Windows has some other mechanisms besides the PATH
envvar for locating pathless executables. Maybe it searches implicitly from the current working dir first? And maybe there was some other set of dirs configured in the registry in addition to the current working dir and the PATH
envvar? I'm unable to locate a reference, but those would be fine additions to ExecutableDirs
.
Ah, found a useful looking reference: https://docs.microsoft.com/en-gb/windows/win32/shell/app-registration#finding-an-application-executable
"App Paths" doesn't seem like something that would fit in the concept of ExecutableDirs
though. But the current working dir and the Windows
and Windows\System32
dirs would.