-
Notifications
You must be signed in to change notification settings - Fork 8
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
feat: adds basic support for XDG dirs #1
feat: adds basic support for XDG dirs #1
Conversation
1b2a5d1
to
66523ef
Compare
Cleaned up the error handling and added another option to control the path after |
Fixes #2. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR! Looks good overall, just a few questions before we move forward
README.md
Outdated
`$XDG_CONFIG_HOME/<@tmux-which-key-xdg-plugin-path>/config.yaml` | ||
and the init file to | ||
`$XDG_DATA_HOME/<@tmux-which-key-xdg-plugin-path>/init.tmux`. | ||
The allows the plugin to also be used with immutable or declarative operating |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The allows the plugin to also be used with immutable or declarative operating | |
This allows the plugin to also be used with immutable or declarative operating |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo on my part. I can make this change. I'll get that in within a day or two.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updates made. Reworded a few things, so let me know if this works.
plugin.sh.tmux
Outdated
echo "[tmux-which-key] XDG_CONFIG_HOME: $XDG_CONFIG_HOME does not exist" | ||
exit 1 | ||
fi | ||
if [ -z "$XDG_DATA_HOME" ]; then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't read the XDG spec, but my understanding from the issue you linked is we should default to $HOME/.local/share
if XDG_DATA_HOME
is unset, instead of returning an error. Should we change this behavior?
Same comment for XDG_CONFIG_HOME
if the spec defines a fallback for that dir
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I can make this change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changes made. Added a function make_xdg_path
to follow the spec which states:
If, when attempting to write a file, the destination directory is non-existent an attempt should be made to create it with permission 0700. If the destination directory exists already the permissions should not be changed.
I did add a dependency of realpath
to avoid that function from creating a bunch of directories that could be caused with a bad relative path. If you would like to remove it, I can.
plugin.sh.tmux
Outdated
exit 1 | ||
fi | ||
if [ ! -d "$XDG_DATA_HOME" ]; then | ||
echo "[tmux-which-key] XDG_CONFIG_HOME: $XDG_DATA_HOME does not exist" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does the spec say to return an error if an XDG dir doesn't exist? I ask because it seems possible to just mkdir -p
it if missing. No strong opinion either way
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was being overly cautious, but I can make this change.
Yes, we can create the directory. It does involve a little extra work. I am thinking the basic flow is:
- If it exists, use it.
- If it doesn't, create it with 0700.
- Raise an error if for some reason these directories are not writeable or cannot be created.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The spec states:
The application should be prepared to handle the case where the file could not be written, either because the directory was non-existent and could not be created, or for any other reason. In such case it may choose to present an error message to the user.
With the earlier changes to use a default directory and create all paths that do not exist so long as they are contained in $HOME
, this error would then be generated by mkdir -p
in the new code. In the existing code it would be generated by cp
which is where it errors now with Nix.
I can make the requested changes over the next day or two. I'll comb through the full spec to look for any nuances that may need to be considered. Here is the link to the actual spec: https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html. |
Changes have been made. Let me know if these work. Thanks for the feedback. |
35fe463
to
c16db5f
Compare
Adds some additional control over the config and init file locations.
When installed with an immutable/declarative OS, the plugin directory is read-only.
Could probably use some more rigid assignments of those paths for full XDG support (see the discussion at tmux-plugins/tmux-resurrect#348).
When I get a moment, I can dig in some more, but for now I wanted to share some minimal changes that make this plugin usable with Nix.