<a href="https://github.com/adrg/xdg/actions/workflows/tests.yml">
<img alt="Tests status" src="https://github.com/adrg/xdg/actions/workflows/tests.yml/badge.svg">
</a>
<a href="https://app.codecov.io/gh/adrg/xdg">
<img alt="Code coverage" src="https://codecov.io/gh/adrg/xdg/branch/master/graphs/badge.svg?branch=master">
</a>
<a href="https://pkg.go.dev/github.com/adrg/xdg">
<img alt="pkg.go.dev documentation" src="https://img.shields.io/badge/go.dev-reference-007d9c?logo=go&logoColor=white">
</a>
<a href="https://opensource.org/licenses/MIT" rel="nofollow">
<img alt="MIT license" src="https://img.shields.io/github/license/adrg/xdg">
</a>
<a href="https://goreportcard.com/report/github.com/adrg/xdg">
<img alt="Go report card" src="https://goreportcard.com/badge/github.com/adrg/xdg">
</a>
<a href="https://github.com/avelino/awesome-go#configuration">
<img alt="Awesome Go" src="https://awesome.re/mentioned-badge.svg">
</a>
<a href="https://github.com/adrg/xdg/graphs/contributors">
<img alt="GitHub contributors" src="https://img.shields.io/github/contributors/adrg/xdg" />
</a>
<a href="https://github.com/adrg/xdg/issues">
<img alt="GitHub open issues" src="https://img.shields.io/github/issues-raw/adrg/xdg">
</a>
<a href="https://ko-fi.com/T6T72WATK">
<img alt="Buy me a coffee" src="https://img.shields.io/static/v1.svg?label=%20&message=Buy%20me%20a%20coffee&color=579fbf&logo=buy%20me%20a%20coffee&logoColor=white">
</a>
Provides an implementation of the XDG Base Directory Specification. The specification defines a set of standard paths for storing application files, including data and configuration files. For portability and flexibility reasons, applications should use the XDG defined locations instead of hardcoding paths.
The package also includes the locations of well known user directories,
support for the non-standard XDG_BIN_HOME directory, as well as other common directories such as fonts and applications.
The current implementation supports most flavors of Unix, Windows, macOS and Plan 9.
On Windows, where XDG environment variables are not usually set, the package uses Known Folders
as defaults. Therefore, appropriate locations are used for common folders which may have been redirected.
See usage examples below. Full documentation can be found at https://pkg.go.dev/github.com/adrg/xdg.
go get github.com/adrg/xdg
The package defines sensible defaults for XDG variables which are empty or not present in the environment.
Unix-like operating systems
Unix
macOS
| <a href="#xdg-base-directory"><img width="500" height="0"></a>
Plan 9
| | :------------------------------------------------------------: | :-----------------------------------------------------------------------: | :-------------------------------------------------------------------------------------------------------------------------------------------------: | :-------------------------------------------------------------------------: | | XDG_DATA_HOME | ~/.local/share | ~/Library/Application Support | $home/lib | | XDG_DATA_DIRS | /usr/local/share
/usr/share | /Library/Application Support~/.local/share | /lib | | XDG_CONFIG_HOME | ~/.config | ~/Library/Application Support | $home/lib | | XDG_CONFIG_DIRS | /etc/xdg | ~/Library/Preferences
/Library/Application Support
/Library/Preferences
~/.config | /lib | | XDG_STATE_HOME | ~/.local/state | ~/Library/Application Support | $home/lib/state | | XDG_CACHE_HOME | ~/.cache | ~/Library/Caches | $home/lib/cache | | XDG_RUNTIME_DIR | /run/user/$UID | ~/Library/Application Support | /tmp | | XDG_BIN_HOME | ~/.local/bin | ~/.local/bin | $home/bin |
Microsoft Windows
Known Folder(s)
Fallback(s)
| | :------------------------------------------------------------: | :---------------------------------------------------------------------------------------: | :------------------------------------------------------------------------------: | | XDG_DATA_HOME | LocalAppData | %LOCALAPPDATA% | | XDG_DATA_DIRS | RoamingAppData
ProgramData | %APPADATA%
%ProgramData% | | XDG_CONFIG_HOME | LocalAppData | %LOCALAPPDATA% | | XDG_CONFIG_DIRS | ProgramData
RoamingAppData | %ProgramData%
%APPDATA% | | XDG_STATE_HOME | LocalAppData | %LOCALAPPDATA% | | XDG_CACHE_HOME | LocalAppData\cache | %LOCALAPPDATA%\cache | | XDG_RUNTIME_DIR | LocalAppData | %LOCALAPPDATA% | | XDG_BIN_HOME | UserProgramFiles | %LOCALAPPDATA%\Programs |
XDG user directories environment variables are usually not set on most operating systems. However, if they are present in the environment, they take precedence. Appropriate fallback locations are used for the environment variables which are not set.
Lastly, default locations are used for any user directories which are not set, as shown in the following tables.
Unix-like operating systems
Unix
macOS
Plan 9
| | :--------------------------------------------------------------: | :-------------------------------------------------------------------------: | :---------------------------------------------------------------------------: | :---------------------------------------------------------------------------: | | XDG_DESKTOP_DIR | ~/Desktop | ~/Desktop | $home/desktop | | XDG_DOWNLOAD_DIR | ~/Downloads | ~/Downloads | $home/downloads | | XDG_DOCUMENTS_DIR | ~/Documents | ~/Documents | $home/documents | | XDG_MUSIC_DIR | ~/Music | ~/Music | $home/music | | XDG_PICTURES_DIR | ~/Pictures | ~/Pictures | $home/pictures | | XDG_VIDEOS_DIR | ~/Videos | ~/Movies | $home/videos | | XDG_TEMPLATES_DIR | ~/Templates | ~/Templates | $home/templates | | XDG_PUBLICSHARE_DIR | ~/Public | ~/Public | $home/public |
Microsoft W