Skip to content

Instantly share code, notes, and snippets.

@garthk
Created August 30, 2023 21:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save garthk/d493a29a87e86e5c9876753aa836b668 to your computer and use it in GitHub Desktop.
Save garthk/d493a29a87e86e5c9876753aa836b668 to your computer and use it in GitHub Desktop.
zsh XDG directory specification environment variables plugin
XDG_DATA_DIRS=/usr/local/share:/usr/share
XDG_CONFIG_DIRS=/etc/xdg
case $(uname) in
Linux)
XDG_CONFIG_HOME="$HOME/.config"
XDG_CACHE_HOME="$HOME/.cache"
XDG_DATA_HOME="$HOME/.local/share"
XDG_STATE_HOME="$HOME/.local/state"
XDG_RUNTIME_DIR="/run/user/$(id -u)"
;;
Darwin)
XDG_CONFIG_DIRS="/Library/Application Support:$XDG_CONFIG_DIRS"
XDG_DATA_DIRS="/Library:$XDG_DATA_DIRS"
XDG_CACHE_HOME="$HOME/Library/Caches"
XDG_CONFIG_HOME="$HOME/Library/Application Support"
XDG_DATA_HOME="$HOME/Library/Application Support"
XDG_RUNTIME_DIR="$HOME/Library/Caches/TemporaryItems"
XDG_STATE_HOME="$HOME/Library/Application Support"
;;
esac
export XDG_CONFIG_DIRS XDG_DATA_DIRS XDG_CACHE_HOME XDG_CONFIG_HOME XDG_DATA_HOME XDG_RUNTIME_DIR XDG_STATE_HOME
@garthk
Copy link
Author

garthk commented Aug 30, 2023

Sets variables according to the [XDG Base Directory Specification])https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html). Tailored for macOS with reference to File System Basics. See in particular its advice regarding ~/Library/Preferences that:

You should not create files in this directory yourself

… hence XDG_CONFIG_HOME not using it.

Do let me know if you've any references that'll guide changes!

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