Skip to main content

Module user_dirs

Module user_dirs 

Source
Expand description

The XDG user directories — Documents, Downloads, Pictures, Music, Videos, Desktop — read from ~/.config/user-dirs.dirs rather than hardcoded, so a sidebar built on a machine set up in another language shows that language’s own folder names instead of a translated set of English guesses sitting next to directories that don’t exist.

xdg-user-dirs-update writes lines like:

XDG_DOCUMENTS_DIR="$HOME/Dokumente"

— one KEY="value" pair per line, $HOME a literal prefix to be substituted, #-comments and blank lines allowed anywhere. This parses exactly that shape and nothing more: no shell expansion beyond the one $HOME substitution the format actually uses, because a general shell parser is a dependency this crate does not need for a file with eight fixed keys.

Here rather than in hyprforge-files-core, where it started, because the photo viewer’s sidebar needs Pictures and Downloads too, and the alternatives were a dependency on the whole file browser or a second parser. hyprforge-files-core re-exports it as xdg_user_dirs.

Structs§

UserDirs
The subset of XDG user directories a sidebar cares about. None for a directory the file doesn’t mention — a partially customised file is common (someone deletes the XDG_TEMPLATES_DIR line and nothing else), and a missing key is not this module’s business to guess at; a sidebar built from it simply won’t offer a shortcut for it.

Functions§

fallback
The conventional English names, used only when there is no user-dirs.dirs to read at all (see load). A sidebar still checks each of these against the real filesystem before offering it, so a guess that doesn’t exist on this machine is dropped rather than shown as a dead shortcut.
load
Reads and parses user-dirs.dirs from the config directory, or falls back to the conventional English names under home if the file isn’t there.
parse
Parses the contents of a user-dirs.dirs file. home is substituted for a leading $HOME in each value, matching how xdg-user-dirs itself writes the file.