sd-path: expose XDG 'projects' user dir
As per: https://blog.tenstral.net/2026/04/hello-projects-directory.html
This commit is contained in:
committed by
Luca Boccassi
parent
c955e24916
commit
a4256a9b31
@@ -68,6 +68,7 @@
|
||||
<constant>SD_PATH_USER_PUBLIC</constant>,
|
||||
<constant>SD_PATH_USER_TEMPLATES</constant>,
|
||||
<constant>SD_PATH_USER_DESKTOP</constant>,
|
||||
<constant>SD_PATH_USER_PROJECTS</constant>,
|
||||
|
||||
<constant>SD_PATH_SEARCH_BINARIES</constant>,
|
||||
<constant>SD_PATH_SEARCH_BINARIES_DEFAULT</constant>,
|
||||
|
||||
@@ -282,6 +282,9 @@ static int get_path(uint64_t type, char **buffer, const char **ret) {
|
||||
case SD_PATH_USER_DESKTOP:
|
||||
return from_xdg_user_dir("XDG_DESKTOP_DIR", buffer, ret);
|
||||
|
||||
case SD_PATH_USER_PROJECTS:
|
||||
return from_xdg_user_dir("XDG_PROJECTS_DIR", buffer, ret);
|
||||
|
||||
case SD_PATH_SYSTEMD_UTIL:
|
||||
*ret = PREFIX_NOSLASH "/lib/systemd";
|
||||
return 0;
|
||||
|
||||
@@ -61,6 +61,7 @@ static const char* const path_table[_SD_PATH_MAX] = {
|
||||
[SD_PATH_USER_PUBLIC] = "user-public",
|
||||
[SD_PATH_USER_TEMPLATES] = "user-templates",
|
||||
[SD_PATH_USER_DESKTOP] = "user-desktop",
|
||||
[SD_PATH_USER_PROJECTS] = "user-projects",
|
||||
|
||||
[SD_PATH_SEARCH_BINARIES] = "search-binaries",
|
||||
[SD_PATH_SEARCH_BINARIES_DEFAULT] = "search-binaries-default",
|
||||
|
||||
@@ -132,6 +132,8 @@ __extension__ enum {
|
||||
SD_PATH_USER_CREDENTIAL_STORE_ENCRYPTED,
|
||||
SD_PATH_USER_SEARCH_CREDENTIAL_STORE_ENCRYPTED,
|
||||
|
||||
SD_PATH_USER_PROJECTS,
|
||||
|
||||
_SD_PATH_MAX,
|
||||
_SD_PATH_INVALID = UINT64_MAX
|
||||
};
|
||||
|
||||
@@ -39,6 +39,7 @@ XDG_DOCUMENTS_DIR="$HOME/top/secret/documents"
|
||||
XDG_MUSIC_DIR="/tmp/vaporwave"
|
||||
XDG_PICTURES_DIR="$HOME/Pictures"
|
||||
XDG_VIDEOS_DIR="$HOME/🤔"
|
||||
XDG_PROJECTS_DIR="$HOME/my-projects"
|
||||
EOF
|
||||
|
||||
systemd-path --help
|
||||
@@ -66,12 +67,13 @@ assert_eq "$(systemd-path user-pictures)" "/root/Pictures"
|
||||
assert_eq "$(systemd-path user-public)" "/root/cat-pictures"
|
||||
assert_eq "$(systemd-path user-templates)" "/templates"
|
||||
assert_eq "$(systemd-path user-videos)" "/root/🤔"
|
||||
assert_eq "$(systemd-path user-projects)" "/root/my-projects"
|
||||
|
||||
# Remove the user-dirs.dir file and check the defaults
|
||||
rm -fv "$USER_DIRS_CONF"
|
||||
[[ ! -e "$USER_DIRS_CONF" ]]
|
||||
assert_eq "$(systemd-path user-desktop)" "/root/Desktop"
|
||||
for dir in "" documents download music pictures public templates videos; do
|
||||
for dir in "" documents download music pictures public templates videos projects; do
|
||||
assert_eq "$(systemd-path "user${dir:+-$dir}")" "/root"
|
||||
done
|
||||
|
||||
|
||||
Reference in New Issue
Block a user