Skip to content

Commit

Permalink
Add full example getting XDG user directory to readme (#2536)
Browse files Browse the repository at this point in the history
  • Loading branch information
laniakea64 authored Dec 22, 2024
1 parent 6a2edd9 commit 82415e5
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1927,8 +1927,18 @@ details.
- `home_directory()` - The user's home directory.

If you would like to use XDG base directories on all platforms you can use the
`env(…)` function with the appropriate environment variable, e.g.,
`env('XDG_CACHE_HOME')`.
`env(…)` function with the appropriate environment variable and fallback,
although note that the XDG specificiation requires ignoring non-absolute paths,
so for full compatibility with spec-complient applications, you would need to
do:

```just
xdg_config_dir := if env('XDG_CONFIG_HOME', '') =~ '^/' {
env('XDG_CONFIG_HOME')
} else {
home_directory() / '.config'
}
```

### Constants

Expand Down

0 comments on commit 82415e5

Please sign in to comment.