Advertisement
j0h

XDG Feature Request

j0h
Apr 5th, 2025
21
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.50 KB | None | 0 0
  1. Support for Environment Variable Expansion in .desktop Exec Keys
  2.  
  3. Please consider allowing simple environment variable expansion (e.g. $HOME, $XDG_DATA_DIRS) in
  4. the Exec key of .desktop files, as defined in the XDG Desktop Entry Specification.
  5. Currently, .desktop entries require fully hardcoded absolute paths in the Exec key.
  6. This imposes several limitations:
  7. * User portability: Applications installed in per-user locations (e.g., within $HOME/.local/bin) must hardcode the username or path in each .desktop file,
  8. making them fragile when moved between systems or user accounts.
  9. * Dynamic environments: Many modern scripts and tools are aware of or depend on XDG_* environment variables, but .desktop files cannot make use of them.
  10. * Autostart scripts: Users creating .desktop entries in ~/.config/autostart/ for user login tasks must avoid $HOME and write out full paths, which is inelegant and error-prone.
  11. * Tooling complexity: Tools that generate .desktop files must resolve these values at generation time, leading to duplication of logic that could otherwise be standardized.
  12. * Script/package integration: Developers often write scripts or installer routines that dynamically generate .desktop files.
  13. These scripts could be greatly simplified by supporting environment variable expansion,
  14. removing the need for runtime resolution or complex path detection logic.
  15.  
  16. Allow a restricted and clearly defined set of environment variables to be expanded at runtime only in the Exec key, such as:
  17.  
  18. $HOME $USER
  19. $XDG_CONFIG_DIRS $XDG_SEAT $XDG_SESSION_PATH
  20. $XDG_CURRENT_DESKTOP $XDG_SEAT_PATH $XDG_SESSION_TYPE
  21. $XDG_DATA_DIRS $XDG_SESSION_CLASS $XDG_VTNR
  22. $XDG_GREETER_DATA_DIR $XDG_SESSION_DESKTOP
  23. $XDG_RUNTIME_DIR $XDG_SESSION_ID
  24.  
  25. This could be optionally restricted to known safe variables to prevent arbitrary command execution, and/or specified in a new metadata key such as:
  26. X-Exec-Allow-Env=true
  27.  
  28. Alternatively, expansion could be limited to environment variables already defined in the session, without permitting subshells or command substitution.
  29. This change would improve the flexibility and portability of .desktop files while remaining consistent with the XDG design goals.
  30. It would empower users and developers to write cleaner,
  31. more adaptable launch entries and reduce friction when scripting automation of .desktop files.
  32.  
  33. If this functionality is indeed present, pardon me, perhaps I need to update or something.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement