-
-
Notifications
You must be signed in to change notification settings - Fork 437
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
Windows tilde expansion and multiple config / theme paths #975
base: master
Are you sure you want to change the base?
Conversation
Any reason to not support XDG env on Windows other than just "consistency" (not followed by bunch of apps like git)? |
There would still need to be a fallback for when xdg environment variables are not set. In that case it makes sense for |
The 'xdg' package used before this PR did not support this env variable either way, since it strictly didn't support Windows at all. Removing it didn't change that. We can now support multiple paths anyway with this PR so more can be added if that's required |
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: ofersadan85 The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
Added a small fix for this compiler warning, as this was also relevant to Windows only:
|
Adding XDG support cross-platform for this would be fairly simple. For all directories in the array [ $XDG_CONFIG_HOME, ...$XDG_CONFIG_DIRS, $HOME/.config, $APPDATA, $LOCALAPPDATA, $USERPROFILE/.config ], if the directory exists and 'lsd' is accessible within it, look for the config file within that 'lsd' subdirectory. If the config file is not found, proceed to the next directory. The only platform specific issue would likely be the split of the $XDG_CONFIG_DIRS directory list, which is separated by ':' on POSIX and ';' on WinOS. The described method works as the XDG spec expects and falls back to reasonable defaults on all platforms (including WinOS). Less platform-specific code which should be a win-win for both devs and users. |
I tend to agree with this, but like I said before, this is a bigger change that can wait for after this PR in my opinion. This PR only adds some functionality to reuse code between Windows and other OSs when searching for paths (i.e. using the logic within |
sorry for the late reply, I am in a sick leave, it may need days to get back 🤧 |
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.
this mostly LGTM, thanks so much @ofersadan85.
only a question commented, and I remember there may be some CI compiler issues when upgrading dirs
to 5.x
, let's run the CI to check it
#[cfg(not(windows))] | ||
pub fn config_file_path() -> Option<PathBuf> { | ||
use xdg::BaseDirectories; | ||
match BaseDirectories::with_prefix(CONF_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.
with this change, can we handle the cases where people change the XDG_CONFIG_HOME
env?
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.
with this change, can we handle the cases where people change the
XDG_CONFIG_HOME
env?
The xdg::BseDirectories
was never available on Windows, since xdg
doesn't support Windows at all. See here
It is possible to just add more possible paths ourselves, now that this can support multiple paths
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.
And internally, dirs
already uses this variable anyway, so we are using it too, see here
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.
this is used in not windows, according to https://docs.rs/dirs/5.0.1/dirs/fn.config_dir.html, linux will remain the XDG env, but not macOS, it seems like a breaking change for macOS users?
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.
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.
it breaks macos: https://github.com/dirs-dev/dirs-rs/blob/main/src/mac.rs#L10C54-L10C54
xdg crate would check the env in macOS
I tested locally
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.
Understood, I'll find a solution to solve this problem and revert back to xdg on any OS that isn't Windows
yes, let's leave that enhancement to another PR |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #975 +/- ##
==========================================
- Coverage 84.51% 84.41% -0.10%
==========================================
Files 51 51
Lines 5068 5075 +7
==========================================
+ Hits 4283 4284 +1
- Misses 785 791 +6 ☔ View full report in Codecov by Sentry. |
hi @ofersadan85, do you have time for this PR? it seems the CI also needs to be fixed. |
I apologize again for the delay, I can't find time for this yet. I'll try again soon but feel free to send it off to someone else if it seems more urgent than I can handle |
hi @ofersadan85, I have rebased your branch, but not able to push to your repo, so I created another PR: #999, should we merge #999 or you pick my change into this one? |
This PR adds some features that I was really missing in
lsd
:lsd ~
on windows #903config.yml
andconfig.yaml
as they are both very common (.yml especially on Windows, as most Windows users are used to 3 letter extensions).$XDG_CONFIG_HOME/lsd
or$HOME/.config/lsd
on non-Windows platforms, and both%APPDATA%\lsd
or%USERPROFILE%\.config\lsd
on Windows. This is important for consistency with normal dotfiles for other apps. Fixes Windows support for.config/lsd
#758xdg
internally, and using onlydir
is more consistent and reliable for all systems.TODO
cargo fmt