diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml
index 4b93df5..edce37a 100644
--- a/.github/workflows/ci.yaml
+++ b/.github/workflows/ci.yaml
@@ -9,7 +9,7 @@ jobs:
build:
strategy:
matrix:
- go: ['1.14']
+ go: ['1.16']
os: [ubuntu-latest, macos-latest, windows-latest]
runs-on: ${{ matrix.os }}
steps:
diff --git a/README.md b/README.md
index e4f4312..5a2ecb8 100644
--- a/README.md
+++ b/README.md
@@ -44,7 +44,7 @@ applications should use the XDG defined locations instead of hardcoding paths.
The package also includes the locations of well known [user directories](https://wiki.archlinux.org/index.php/XDG_user_directories)
and an implementation of the [state directory](https://wiki.debian.org/XDGBaseDirectorySpecification#Proposal:_STATE_directory) proposal.
-Windows, macOS and most flavors of Unix are supported.
+Most flavors of Unix, Windows, macOS and Plan 9 are supported.
Full documentation can be found at: https://pkg.go.dev/github.com/adrg/xdg.
@@ -58,75 +58,56 @@ present in the environment.
#### XDG Base Directory
-| | Unix | macOS | Windows |
-| :-------------- | :---------------------------------- | :------------------------------------------------------------------------------------ | :-------------------------------------- |
-| XDG_DATA_HOME | `~/.local/share` | `~/Library/Application Support` | `%LOCALAPPDATA%` |
-| XDG_DATA_DIRS | `/usr/local/share`
`/usr/share` | `/Library/Application Support` | `%APPDATA%\Roaming`
`%PROGRAMDATA%` |
-| XDG_CONFIG_HOME | `~/.config` | `~/Library/Application Support` | `%LOCALAPPDATA%` |
-| XDG_CONFIG_DIRS | `/etc/xdg` | `~/Library/Preferences`
`/Library/Application Support`
`/Library/Preferences` | `%PROGRAMDATA%` |
-| XDG_CACHE_HOME | `~/.cache` | `~/Library/Caches` | `%LOCALAPPDATA%\cache` |
-| XDG_RUNTIME_DIR | `/run/user/UID` | `~/Library/Application Support` | `%LOCALAPPDATA%` |
+| | Unix | macOS | Windows | Plan 9 |
+| :--------------------------------------------- | :---------------------------------------------------- | :--------------------------------------------------------------------------------------------------------------- | :-------------------------------------------------------- | :------------------------- |
+| XDG_DATA_HOME | ~/.local/share | ~/Library/Application Support | %LOCALAPPDATA% | $home/lib |
+| XDG_DATA_DIRS | /usr/local/share
/usr/share | /Library/Application Support | %APPDATA%\Roaming
%PROGRAMDATA% | /lib |
+| XDG_CONFIG_HOME | ~/.config | ~/Library/Application Support | %LOCALAPPDATA% | $home/lib |
+| XDG_CONFIG_DIRS | /etc/xdg | ~/Library/Preferences
/Library/Application Support
/Library/Preferences | %PROGRAMDATA% | /lib |
+| XDG_CACHE_HOME | ~/.cache | ~/Library/Caches | %LOCALAPPDATA%\cache | $home/lib/cache |
+| XDG_RUNTIME_DIR | /run/user/UID | ~/Library/Application Support | %LOCALAPPDATA% | /tmp |
#### XDG user directories
-| | Unix | macOS | Windows |
-| :------------------ | :------------ | :------------ | :------------------------ |
-| XDG_DESKTOP_DIR | `~/Desktop` | `~/Desktop` | `%USERPROFILE%/Desktop` |
-| XDG_DOWNLOAD_DIR | `~/Downloads` | `~/Downloads` | `%USERPROFILE%/Downloads` |
-| XDG_DOCUMENTS_DIR | `~/Documents` | `~/Documents` | `%USERPROFILE%/Documents` |
-| XDG_MUSIC_DIR | `~/Music` | `~/Music` | `%USERPROFILE%/Music` |
-| XDG_PICTURES_DIR | `~/Pictures` | `~/Pictures` | `%USERPROFILE%/Pictures` |
-| XDG_VIDEOS_DIR | `~/Videos` | `~/Movies` | `%USERPROFILE%/Videos` |
-| XDG_TEMPLATES_DIR | `~/Templates` | `~/Templates` | `%USERPROFILE%/Templates` |
-| XDG_PUBLICSHARE_DIR | `~/Public` | `~/Public` | `%PUBLIC%` |
+| | Unix | macOS | Windows | Plan 9 |
+| :------------------------------------------------- | :--------------------- | :--------------------- | :--------------------------------- | :------------------------- |
+| XDG_DESKTOP_DIR | ~/Desktop | ~/Desktop | %USERPROFILE%\Desktop | $home/desktop |
+| XDG_DOWNLOAD_DIR | ~/Downloads | ~/Downloads | %USERPROFILE%\Downloads | $home/downloads |
+| XDG_DOCUMENTS_DIR | ~/Documents | ~/Documents | %USERPROFILE%\Documents | $home/documents |
+| XDG_MUSIC_DIR | ~/Music | ~/Music | %USERPROFILE%\Music | $home/music |
+| XDG_PICTURES_DIR | ~/Pictures | ~/Pictures | %USERPROFILE%\Pictures | $home/pictures |
+| XDG_VIDEOS_DIR | ~/Videos | ~/Movies | %USERPROFILE%\Videos | $home/videos |
+| XDG_TEMPLATES_DIR | ~/Templates | ~/Templates | %USERPROFILE%\Templates | $home/templates |
+| XDG_PUBLICSHARE_DIR | ~/Public | ~/Public | %PUBLIC% | $home/public |
#### Non-standard directories
State directory
-```
-Unix
- • ~/.local/state
-macOS
- • ~/Library/Application Support
-Windows
- • %LOCALAPPDATA%
-```
+| | Unix | macOS | Windows | Plan 9 |
+| :-------------------------------------------- | :------------------------ | :--------------------------------------- | :------------------------ | :------------------------- |
+| XDG_STATE_HOME | ~/.local/state | ~/Library/Application Support | %LOCALAPPDATA% | $home/lib/state |
Application directories
-```
-Unix
- • $XDG_DATA_HOME/applications
- • ~/.local/share/applications
- • /usr/local/share/applications
- • /usr/share/applications
- • $XDG_DATA_DIRS/applications
-macOS
- • /Applications
-Windows
- • %APPDATA%\Roaming\Microsoft\Windows\Start Menu\Programs
-```
+| Unix | macOS | Windows | Plan 9 |
+| :--------------------------------------- | :----------------------- | :----------------------------------------------------------------- | :-------------------- |
+| $XDG_DATA_HOME/applications | /Applications | %APPDATA%\Roaming\Microsoft\Windows\Start Menu\Programs | $home/bin |
+| ~/.local/share/applications | | | /bin |
+| /usr/local/share/applications | | | |
+| /usr/share/applications | | | |
+| $XDG_DATA_DIRS/applications | | | |
Font directories
-```
-Unix
- • $XDG_DATA_HOME/fonts
- • ~/.fonts
- • ~/.local/share/fonts
- • /usr/local/share/fonts
- • /usr/share/fonts
- • $XDG_DATA_DIRS/fonts
-macOS
- • ~/Library/Fonts
- • /Library/Fonts
- • /System/Library/Fonts
- • /Network/Library/Fonts
-Windows
- • %windir%\Fonts
- • %LOCALAPPDATA%\Microsoft\Windows\Fonts
-```
+| Unix | macOS | Windows | Plan 9 |
+| :-------------------------------- | :-------------------------------- | :------------------------------------------------ | :------------------------ |
+| $XDG_DATA_HOME/fonts | ~/Library/Fonts | %windir%\Fonts | $home/lib/font |
+| ~/.fonts | /Library/Fonts | %LOCALAPPDATA%\Microsoft\Windows\Fonts | /lib/font |
+| ~/.local/share/fonts | /System/Library/Fonts | | |
+| /usr/local/share/fonts | /Network/Library/Fonts | | |
+| /usr/share/fonts | | | |
+| $XDG_DATA_DIRS/fonts | | | |
## Usage
diff --git a/codecov.yml b/codecov.yml
new file mode 100644
index 0000000..54ee338
--- /dev/null
+++ b/codecov.yml
@@ -0,0 +1,11 @@
+coverage:
+ status:
+ project:
+ default:
+ target: 90%
+ threshold: 1%
+ patch:
+ default:
+ target: 100%
+ignore:
+ - "paths_plan9.go"
diff --git a/paths_plan9.go b/paths_plan9.go
new file mode 100644
index 0000000..05638af
--- /dev/null
+++ b/paths_plan9.go
@@ -0,0 +1,44 @@
+// +build plan9
+
+package xdg
+
+import (
+ "path/filepath"
+)
+
+func initBaseDirs(home string) {
+ homeLibDir := filepath.Join(home, "lib")
+ rootLibDir := "/lib"
+
+ // Initialize base directories.
+ baseDirs.dataHome = xdgPath(envDataHome, homeLibDir)
+ baseDirs.data = xdgPaths(envDataDirs, rootLibDir)
+ baseDirs.configHome = xdgPath(envConfigHome, homeLibDir)
+ baseDirs.config = xdgPaths(envConfigDirs, rootLibDir)
+ baseDirs.cacheHome = xdgPath(envCacheHome, filepath.Join(homeLibDir, "cache"))
+ baseDirs.runtime = xdgPath(envRuntimeDir, "/tmp")
+
+ // Initialize non-standard directories.
+ baseDirs.stateHome = xdgPath(envStateHome, filepath.Join(homeLibDir, "state"))
+
+ baseDirs.applications = []string{
+ filepath.Join(home, "bin"),
+ "/bin",
+ }
+
+ baseDirs.fonts = []string{
+ filepath.Join(homeLibDir, "font"),
+ "/lib/font",
+ }
+}
+
+func initUserDirs(home string) {
+ UserDirs.Desktop = xdgPath(envDesktopDir, filepath.Join(home, "desktop"))
+ UserDirs.Download = xdgPath(envDownloadDir, filepath.Join(home, "downloads"))
+ UserDirs.Documents = xdgPath(envDocumentsDir, filepath.Join(home, "documents"))
+ UserDirs.Music = xdgPath(envMusicDir, filepath.Join(home, "music"))
+ UserDirs.Pictures = xdgPath(envPicturesDir, filepath.Join(home, "pictures"))
+ UserDirs.Videos = xdgPath(envVideosDir, filepath.Join(home, "videos"))
+ UserDirs.Templates = xdgPath(envTemplatesDir, filepath.Join(home, "templates"))
+ UserDirs.PublicShare = xdgPath(envPublicShareDir, filepath.Join(home, "public"))
+}
diff --git a/paths_plan9_test.go b/paths_plan9_test.go
new file mode 100644
index 0000000..32aec86
--- /dev/null
+++ b/paths_plan9_test.go
@@ -0,0 +1,219 @@
+// +build plan9
+
+package xdg_test
+
+import (
+ "path/filepath"
+ "testing"
+
+ "github.com/adrg/xdg"
+)
+
+func TestDefaultBaseDirs(t *testing.T) {
+ home := xdg.Home
+
+ testDirs(t,
+ &envSample{
+ name: "XDG_DATA_HOME",
+ expected: filepath.Join(home, "lib"),
+ actual: &xdg.DataHome,
+ },
+ &envSample{
+ name: "XDG_DATA_DIRS",
+ expected: []string{"/lib"},
+ actual: &xdg.DataDirs,
+ },
+ &envSample{
+ name: "XDG_CONFIG_HOME",
+ expected: filepath.Join(home, "lib"),
+ actual: &xdg.ConfigHome,
+ },
+ &envSample{
+ name: "XDG_CONFIG_DIRS",
+ expected: []string{"/lib"},
+ actual: &xdg.ConfigDirs,
+ },
+ &envSample{
+ name: "XDG_CACHE_HOME",
+ expected: filepath.Join(home, "lib", "cache"),
+ actual: &xdg.CacheHome,
+ },
+ &envSample{
+ name: "XDG_RUNTIME_DIR",
+ expected: "/tmp",
+ actual: &xdg.RuntimeDir,
+ },
+ &envSample{
+ name: "XDG_STATE_HOME",
+ expected: filepath.Join(home, "lib", "state"),
+ actual: &xdg.StateHome,
+ },
+ &envSample{
+ name: "XDG_APPLICATION_DIRS",
+ expected: []string{
+ filepath.Join(home, "bin"),
+ "/bin",
+ },
+ actual: &xdg.ApplicationDirs,
+ },
+ &envSample{
+ name: "XDG_FONT_DIRS",
+ expected: []string{
+ filepath.Join(home, "lib", "font"),
+ "/lib/font",
+ },
+ actual: &xdg.FontDirs,
+ },
+ )
+}
+
+func TestCustomBaseDirs(t *testing.T) {
+ homeLib := filepath.Join(xdg.Home, "lib")
+
+ testDirs(t,
+ &envSample{
+ name: "XDG_DATA_HOME",
+ value: filepath.Join(homeLib, "data"),
+ expected: filepath.Join(homeLib, "data"),
+ actual: &xdg.DataHome,
+ },
+ &envSample{
+ name: "XDG_DATA_DIRS",
+ value: "/lib/data",
+ expected: []string{"/lib/data"},
+ actual: &xdg.DataDirs,
+ },
+ &envSample{
+ name: "XDG_CONFIG_HOME",
+ value: filepath.Join(homeLib, "config"),
+ expected: filepath.Join(homeLib, "config"),
+ actual: &xdg.ConfigHome,
+ },
+ &envSample{
+ name: "XDG_CONFIG_DIRS",
+ value: "/lib/config",
+ expected: []string{"/lib/config"},
+ actual: &xdg.ConfigDirs,
+ },
+ &envSample{
+ name: "XDG_CACHE_HOME",
+ value: homeLib,
+ expected: homeLib,
+ actual: &xdg.CacheHome,
+ },
+ &envSample{
+ name: "XDG_RUNTIME_DIR",
+ value: filepath.Join(homeLib, "runtime"),
+ expected: filepath.Join(homeLib, "runtime"),
+ actual: &xdg.RuntimeDir,
+ },
+ &envSample{
+ name: "XDG_STATE_HOME",
+ value: homeLib,
+ expected: homeLib,
+ actual: &xdg.StateHome,
+ },
+ )
+}
+
+func TestDefaultUserDirs(t *testing.T) {
+ home := xdg.Home
+
+ testDirs(t,
+ &envSample{
+ name: "XDG_DESKTOP_DIR",
+ expected: filepath.Join(home, "desktop"),
+ actual: &xdg.UserDirs.Desktop,
+ },
+ &envSample{
+ name: "XDG_DOWNLOAD_DIR",
+ expected: filepath.Join(home, "downloads"),
+ actual: &xdg.UserDirs.Download,
+ },
+ &envSample{
+ name: "XDG_DOCUMENTS_DIR",
+ expected: filepath.Join(home, "documents"),
+ actual: &xdg.UserDirs.Documents,
+ },
+ &envSample{
+ name: "XDG_MUSIC_DIR",
+ expected: filepath.Join(home, "music"),
+ actual: &xdg.UserDirs.Music,
+ },
+ &envSample{
+ name: "XDG_PICTURES_DIR",
+ expected: filepath.Join(home, "pictures"),
+ actual: &xdg.UserDirs.Pictures,
+ },
+ &envSample{
+ name: "XDG_VIDEOS_DIR",
+ expected: filepath.Join(home, "videos"),
+ actual: &xdg.UserDirs.Videos,
+ },
+ &envSample{
+ name: "XDG_TEMPLATES_DIR",
+ expected: filepath.Join(home, "templates"),
+ actual: &xdg.UserDirs.Templates,
+ },
+ &envSample{
+ name: "XDG_PUBLICSHARE_DIR",
+ expected: filepath.Join(home, "public"),
+ actual: &xdg.UserDirs.PublicShare,
+ },
+ )
+}
+
+func TestCustomUserDirs(t *testing.T) {
+ homeLib := filepath.Join(xdg.Home, "lib")
+
+ testDirs(t,
+ &envSample{
+ name: "XDG_DESKTOP_DIR",
+ value: filepath.Join(homeLib, "desktop"),
+ expected: filepath.Join(homeLib, "desktop"),
+ actual: &xdg.UserDirs.Desktop,
+ },
+ &envSample{
+ name: "XDG_DOWNLOAD_DIR",
+ value: filepath.Join(homeLib, "downloads"),
+ expected: filepath.Join(homeLib, "downloads"),
+ actual: &xdg.UserDirs.Download,
+ },
+ &envSample{
+ name: "XDG_DOCUMENTS_DIR",
+ value: filepath.Join(homeLib, "documents"),
+ expected: filepath.Join(homeLib, "documents"),
+ actual: &xdg.UserDirs.Documents,
+ },
+ &envSample{
+ name: "XDG_MUSIC_DIR",
+ value: filepath.Join(homeLib, "music"),
+ expected: filepath.Join(homeLib, "music"),
+ actual: &xdg.UserDirs.Music,
+ },
+ &envSample{
+ name: "XDG_PICTURES_DIR",
+ value: filepath.Join(homeLib, "pictures"),
+ expected: filepath.Join(homeLib, "pictures"),
+ actual: &xdg.UserDirs.Pictures,
+ },
+ &envSample{
+ name: "XDG_VIDEOS_DIR",
+ value: filepath.Join(homeLib, "videos"),
+ expected: filepath.Join(homeLib, "videos"),
+ actual: &xdg.UserDirs.Videos,
+ },
+ &envSample{
+ name: "XDG_TEMPLATES_DIR",
+ value: filepath.Join(homeLib, "templates"),
+ expected: filepath.Join(homeLib, "templates"),
+ actual: &xdg.UserDirs.Templates,
+ },
+ &envSample{
+ name: "XDG_PUBLICSHARE_DIR",
+ value: filepath.Join(homeLib, "public"),
+ expected: filepath.Join(homeLib, "public"),
+ actual: &xdg.UserDirs.PublicShare,
+ },
+ )
+}