Skip to content
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: use xdg-user-dir to infer desktop, downloads, and other directory #2192

Closed
3 tasks done
UtkarshVerma opened this issue Jan 12, 2025 · 9 comments
Closed
3 tasks done
Labels
feature New feature request

Comments

@UtkarshVerma
Copy link

yazi --debug output

N/A

Please describe the problem you're trying to solve

Currently, the user directory icons are hardcoded at https://github.com/sxyazi/yazi/blob/main/yazi-config/preset/theme-dark.toml#L248.

Since I use lowercased XDG user directories personally, the icons do not apply for me.

Would you be willing to contribute this feature?

  • Yes, I'll give it a shot

Describe the solution you'd like

It would be great if yazi could just infer the XDG directory paths using xdg-user-dir. There's a pre-existing crate for this:

https://docs.rs/xdg-user/latest/xdg_user/

Additional context

No response

Checklist

  • I have searched the existing issues/discussions
  • The latest nightly build doesn't already have this feature
@UtkarshVerma UtkarshVerma added the feature New feature request label Jan 12, 2025
@sxyazi
Copy link
Owner

sxyazi commented Jan 12, 2025

Do you mean finding a way to reference the return value of xdg-user-dir as the icon path rule in the TOML file? Or are you suggesting completely removing the entire dirs rule set, no longer respecting the user's icon configuration, and just hardcoding the return value of xdg-user-dir as the icon rule?

@sxyazi sxyazi added the waiting on op Waiting for more information from the original poster label Jan 12, 2025
@UtkarshVerma
Copy link
Author

UtkarshVerma commented Jan 12, 2025

We could add one more optional field to the icon.dir entry:

[icon]
dirs = [
	{ name = "VIDEOS", type = "xdg", text = "some icon" },
]

When parsing the config, if we hit any entry of type = "xdg", then we use the xdg_user crate to get the path and add the evaluated path - text pair to the icon map. With this, we can remove the existing hardcodes without any loss of functionality.

In case of a clash, we always use the user's icon, so this should not be a breaking change. This is Linux-specific, so we'll probably like to scope it to Linux.

@github-actions github-actions bot removed the waiting on op Waiting for more information from the original poster label Jan 12, 2025
@sxyazi
Copy link
Owner

sxyazi commented Jan 12, 2025

This would mean that if the user's XDG download directory is ~/a, then all directories named a would apply the icon rules, because the name here isn't a full path, it's just the directory name.

Also, I don't think type=xdg is a good solution, at least not with the value "xdg", because it's platform-specific, if a user copies their Yazi config from Linux to macOS to use, they'd find that it doesn't work properly.

@sxyazi sxyazi added the waiting on op Waiting for more information from the original poster label Jan 12, 2025
@sxyazi
Copy link
Owner

sxyazi commented Jan 12, 2025

Maybe we can just make dirs case-insensitive, like globs, files, and exts, which can solve your problem and also make their behavior more consistent.

@UtkarshVerma
Copy link
Author

Yes, it does solve the problem for me, but people could also have it mapped to different names. Since a really neat interface already exists, I think we should make use of it.

@github-actions github-actions bot removed the waiting on op Waiting for more information from the original poster label Jan 12, 2025
@sxyazi
Copy link
Owner

sxyazi commented Jan 12, 2025

If the user renames their download directory to x they must know what they're doing. In this case, it makes more sense for them to add their own icon rules through prepend_dirs or append_dirs, and they also know that any other directory named x will have the same rule applied

@sxyazi
Copy link
Owner

sxyazi commented Jan 12, 2025

Or if x is a more common name, the user would need to use glob rules instead of dir rules to match it more precisely, in order to avoid affecting other directories with the same name. To me, this seems more like a user behavior.

@sxyazi sxyazi added the waiting on op Waiting for more information from the original poster label Jan 12, 2025
@UtkarshVerma
Copy link
Author

Hmm, I still do not wholly agree with that. I would prefer there to be a built-in inference, but it is fine. It's your project and a great one at that. So, I'll be happy with whatever you decide.

Please feel free to close this and let me know if the path is going to be case-insensitive for icons.

@github-actions github-actions bot removed the waiting on op Waiting for more information from the original poster label Jan 12, 2025
@sxyazi
Copy link
Owner

sxyazi commented Jan 12, 2025

Closing as not planned, feel free to raise a PR if having dirs case-insensitive is still useful for you, thanks!

For the future: If anyone else needs it, please file a new issue and propose a cross-platform and more reliable matching method (using full paths instead of just name), maybe going into conds or creating a new rule set.

@sxyazi sxyazi closed this as not planned Won't fix, can't repro, duplicate, stale Jan 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature request
Projects
None yet
Development

No branches or pull requests

2 participants