Skip to content

Conversation

@meee-low
Copy link

@meee-low meee-low commented Dec 17, 2025

Closes #939, following the idea from @cafkafk's comment in that issue.

This relies on the implementation from our dependency dirs. If the user has not set or changed their special directories from the default values, this should have the the exact same output, as it still uses the old string comparison as a fallback.

I have not written tests for this, I welcome some ideas of how to test it. Testing is not trivial, since it's different for each OS family (accounted for by dirs). I have "tested" it locally on my (Linux) machine and it worked as intended.

I think this should also respect localization of those folder names, but I have not tested localizations specifically.

I have left a few comments concerning some icons that don't really match in Windows, since it has a different separation of directories.

Relevant information:
https://wiki.archlinux.org/title/XDG_user_directories
https://specifications.freedesktop.org/basedir/latest/

@meee-low
Copy link
Author

CI seems to have failed before even building the project. Some network error in the bsd tests. Maybe rerunning would solve it?

https://github.com/eza-community/eza/actions/runs/20288034950/job/58266225590?pr=1679#step:3:1194
https://github.com/eza-community/eza/actions/runs/20288034950/job/58266225578?pr=1679#step:3:2207

Copy link
Contributor

@ariasuni ariasuni left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems to work correctly here:

$ bat ~/.config/user-dirs.dirs
XDG_DESKTOP_DIR="$HOME"
XDG_DOCUMENTS_DIR="$HOME/documents"
XDG_DOWNLOAD_DIR="$HOME/téléchargements"
XDG_MUSIC_DIR="$HOME/musique"
XDG_PICTURES_DIR="$HOME/médias"
XDG_PUBLICSHARE_DIR="$HOME/.local/share/Public/"
XDG_TEMPLATES_DIR="$HOME/.local/share/Templates/"
XDG_VIDEOS_DIR="$HOME/médias"
$ cargo run -- -l --icons ~
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.11s
     Running `target/debug/eza -l --icons /home/ariasuni`
drwxr-xr-x - ariasuni 18 déc.  17:46  administratif
drwxr-xr-x - ariasuni 15 déc.  21:47 󰲂 documents
drwxr-xr-x - ariasuni 26 déc.  19:31  'films et séries'
drwxr-xr-x - ariasuni 28 oct.  16:38  jeux
drwxr-xr-x - ariasuni 15 déc.  18:30 󱍙 musique
drwxr-xr-x - ariasuni 15 déc.  16:26  médias
drwxr-xr-x - ariasuni 15 mars  18:17  projets
drwxr-xr-x - ariasuni 29 déc.  14:09 󰉍 téléchargements

So, nice!

I’ll let Windows user comment on what to do about Windows directories.

For the CI we’re working on it: #1669

Comment on lines +1154 to +1166
if let Some(p) = dirs::config_dir() {
// NOTE: maybe we should not use this for Windows, since AppData\Roaming is not really
// a config directory (windows does not split the config and data directories like this)
map.insert(p, Icons::FOLDER_CONFIG);
}

if let Some(p) = dirs::desktop_dir() {
map.insert(p, Icons::FOLDER_DESKTOP);
}

if let Some(p) = dirs::document_dir() {
map.insert(p, Icons::FOLDER_DOCUMENTS);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn’t test it, but I think it would be nicer if it was written like this:

Suggested change
if let Some(p) = dirs::config_dir() {
// NOTE: maybe we should not use this for Windows, since AppData\Roaming is not really
// a config directory (windows does not split the config and data directories like this)
map.insert(p, Icons::FOLDER_CONFIG);
}
if let Some(p) = dirs::desktop_dir() {
map.insert(p, Icons::FOLDER_DESKTOP);
}
if let Some(p) = dirs::document_dir() {
map.insert(p, Icons::FOLDER_DOCUMENTS);
}
// NOTE: maybe we should not use this for Windows, since AppData\Roaming is not really
// a config directory (windows does not split the config and data directories like this)
dirs::config_dir().inspect(|p| map.insert(p, Icons::FOLDER_CONFIG));
dirs::desktop_dir().inspect(|p| map.insert(p, Icons::FOLDER_DESKTOP));
dirs::document_dir().inspect(|p| map.insert(p, Icons::FOLDER_DOCUMENTS));

Everything could then be tightly packed instead of having 3 lines for a simple conditional insert.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: XDG_USER_DIR based icons

2 participants