MCPcopy Index your code
hub / github.com/adrg/xdg

github.com/adrg/xdg @v0.5.3

Chat with this repo
repository ↗ · DeepWiki ↗ · release v0.5.3 ↗ · + Follow
113 symbols 354 edges 24 files 30 documented · 27% 65 cross-repo links updated 7d agov0.5.3 · 2024-10-31★ 1,0064 open issues
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

xdg logo

Go implementation of the XDG Base Directory Specification and XDG user directories.

<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.

Installation

go get github.com/adrg/xdg

Default locations

The package defines sensible defaults for XDG variables which are empty or not present in the environment.

  • On Unix-like operating systems, XDG environment variables are typically defined. Appropriate default locations are used for the environment variables which are not set.
  • On Windows, XDG environment variables are usually not set. If that is the case, the package relies on the appropriate Known Folders. Sensible fallback locations are used for the folders which are not set.

XDG Base Directory

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

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.

  • On Unix-like operating systems (except macOS and Plan 9), the package reads the user-dirs.dirs config file.
  • On Windows, the package uses the appropriate Known Folders.

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

Core symbols most depended-on inside this repo

EnvPath
called by 59
internal/pathutil/pathutil.go
First
called by 37
internal/pathutil/pathutil.go
KnownFolder
called by 27
internal/pathutil/pathutil_windows.go
UserHomeDir
called by 19
internal/pathutil/pathutil_windows.go
ExpandHome
called by 17
internal/pathutil/pathutil_windows.go
Create
called by 12
internal/pathutil/pathutil.go
EnvPathList
called by 11
internal/pathutil/pathutil.go
Reload
called by 10
xdg.go

Shape

Function 98
Method 10
Struct 5

Languages

Go100%

Modules by API surface

xdg.go12 symbols
base_dirs.go11 symbols
example_test.go10 symbols
xdg_test.go8 symbols
internal/pathutil/pathutil.go6 symbols
paths_windows.go5 symbols
paths_unix_test.go5 symbols
paths_plan9_test.go5 symbols
paths_darwin_test.go5 symbols
internal/pathutil/pathutil_windows_test.go5 symbols
internal/pathutil/pathutil_test.go5 symbols
paths_windows_test.go4 symbols

For agents

$ claude mcp add xdg \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact