Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ as shown in the following tables.
| <kbd><b>XDG_VIDEOS_DIR</b></kbd> | <kbd>~/Videos</kbd> | <kbd>~/Movies</kbd> | <kbd>$home/videos</kbd> |
| <kbd><b>XDG_TEMPLATES_DIR</b></kbd> | <kbd>~/Templates</kbd> | <kbd>~/Templates</kbd> | <kbd>$home/templates</kbd> |
| <kbd><b>XDG_PUBLICSHARE_DIR</b></kbd> | <kbd>~/Public</kbd> | <kbd>~/Public</kbd> | <kbd>$home/public</kbd> |
| <kbd><b>XDG_PROJECTS_DIR</b></kbd> | <kbd>~/Projects</kbd> | <kbd>~/Projects</kbd> | <kbd>$home/projects</kbd> |

</details>

Expand All @@ -145,6 +146,7 @@ as shown in the following tables.
| <kbd><b>XDG_VIDEOS_DIR</b></kbd> | <kbd>Videos</kbd> | <kbd>%USERPROFILE%\Videos</kbd> |
| <kbd><b>XDG_TEMPLATES_DIR</b></kbd> | <kbd>Templates</kbd> | <kbd>%APPDATA%\Microsoft\Windows\Templates</kbd> |
| <kbd><b>XDG_PUBLICSHARE_DIR</b></kbd> | <kbd>Public</kbd> | <kbd>%PUBLIC%</kbd> |
| <kbd><b>XDG_PROJECTS_DIR</b></kbd> | - | <kbd>%USERPROFILE%\Projects</kbd> |

</details>

Expand Down Expand Up @@ -261,6 +263,7 @@ func main() {
log.Println("Videos directory:", xdg.UserDirs.Videos)
log.Println("Templates directory:", xdg.UserDirs.Templates)
log.Println("Public directory:", xdg.UserDirs.PublicShare)
log.Println("Projects directory:", xdg.UserDirs.Projects)
}
```

Expand Down
1 change: 1 addition & 0 deletions doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ XDG user directories
log.Println("Videos directory:", xdg.UserDirs.Videos)
log.Println("Templates directory:", xdg.UserDirs.Templates)
log.Println("Public directory:", xdg.UserDirs.PublicShare)
log.Println("Projects directory:", xdg.UserDirs.Projects)
}
*/
package xdg
1 change: 1 addition & 0 deletions internal/userdirs/config_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ func ParseConfig(r io.Reader) (*Directories, error) {
EnvVideosDir: &dirs.Videos,
EnvTemplatesDir: &dirs.Templates,
EnvPublicShareDir: &dirs.PublicShare,
EnvProjectsDir: &dirs.Projects,
}

scanner := bufio.NewScanner(r)
Expand Down
2 changes: 2 additions & 0 deletions internal/userdirs/config_unix_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ func TestParseConfig(t *testing.T) {
XDG_MUSIC_DIR="$HOME/Music" # Music user directory
# XDG_PICTURES_DIR="$HOME/Pictures"
XDG_VIDEOS_DIR=""
XDG_PROJECTS_DIR="$HOME/Projects"

NON_XDG_DIR="ignore"
XDG_INVALID_DIR="ignore"
Expand All @@ -72,6 +73,7 @@ func TestParseConfig(t *testing.T) {
require.Equal(t, filepath.Join(home, "Music"), dirs.Music)
require.Equal(t, "", dirs.Pictures)
require.Equal(t, "", dirs.Videos)
require.Equal(t, filepath.Join(home, "Projects"), dirs.Projects)

// Test reader error.
f, err := os.CreateTemp("", "test_parse_config")
Expand Down
4 changes: 4 additions & 0 deletions internal/userdirs/userdirs.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const (
EnvVideosDir = "XDG_VIDEOS_DIR"
EnvTemplatesDir = "XDG_TEMPLATES_DIR"
EnvPublicShareDir = "XDG_PUBLICSHARE_DIR"
EnvProjectsDir = "XDG_PROJECTS_DIR"
)

// Directories defines the locations of well known user directories.
Expand Down Expand Up @@ -37,4 +38,7 @@ type Directories struct {

// PublicShare defines a suitable location for user shared files.
PublicShare string

// Projects defines a suitable location for user projects.
Projects string
}
1 change: 1 addition & 0 deletions paths_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,5 @@ func initUserDirs(home string) {
UserDirs.Videos = pathutil.EnvPath(userdirs.EnvVideosDir, filepath.Join(home, "Movies"))
UserDirs.Templates = pathutil.EnvPath(userdirs.EnvTemplatesDir, filepath.Join(home, "Templates"))
UserDirs.PublicShare = pathutil.EnvPath(userdirs.EnvPublicShareDir, filepath.Join(home, "Public"))
UserDirs.Projects = pathutil.EnvPath(userdirs.EnvProjectsDir, filepath.Join(home, "Projects"))
}
11 changes: 11 additions & 0 deletions paths_darwin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,11 @@ func TestDefaultUserDirs(t *testing.T) {
expected: filepath.Join(home, "Public"),
actual: &xdg.UserDirs.PublicShare,
},
&envSample{
name: "XDG_PROJECTS_DIR",
expected: filepath.Join(home, "Projects"),
actual: &xdg.UserDirs.Projects,
},
)
}

Expand Down Expand Up @@ -245,6 +250,12 @@ func TestCustomUserDirs(t *testing.T) {
expected: filepath.Join(home, "Library/Public"),
actual: &xdg.UserDirs.PublicShare,
},
&envSample{
name: "XDG_PROJECTS_DIR",
value: "$HOME/Library/Projects",
expected: filepath.Join(home, "Library/Projects"),
actual: &xdg.UserDirs.Projects,
},
)
}

Expand Down
1 change: 1 addition & 0 deletions paths_plan9.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,5 @@ func initUserDirs(home string) {
UserDirs.Videos = pathutil.EnvPath(userdirs.EnvVideosDir, filepath.Join(home, "videos"))
UserDirs.Templates = pathutil.EnvPath(userdirs.EnvTemplatesDir, filepath.Join(home, "templates"))
UserDirs.PublicShare = pathutil.EnvPath(userdirs.EnvPublicShareDir, filepath.Join(home, "public"))
UserDirs.Projects = pathutil.EnvPath(userdirs.EnvProjectsDir, filepath.Join(home, "projects"))
}
11 changes: 11 additions & 0 deletions paths_plan9_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,11 @@ func TestDefaultUserDirs(t *testing.T) {
expected: filepath.Join(home, "public"),
actual: &xdg.UserDirs.PublicShare,
},
&envSample{
name: "XDG_PROJECTS_DIR",
expected: filepath.Join(home, "projects"),
actual: &xdg.UserDirs.Projects,
},
)
}

Expand Down Expand Up @@ -228,6 +233,12 @@ func TestCustomUserDirs(t *testing.T) {
expected: filepath.Join(homeLib, "public"),
actual: &xdg.UserDirs.PublicShare,
},
&envSample{
name: "XDG_PROJECTS_DIR",
value: filepath.Join(homeLib, "projects"),
expected: filepath.Join(homeLib, "projects"),
actual: &xdg.UserDirs.Projects,
},
)
}

Expand Down
1 change: 1 addition & 0 deletions paths_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,5 @@ func initUserDirs(home, configHome string) {
UserDirs.Videos = pathutil.EnvPath(userdirs.EnvVideosDir, dirs.Videos, filepath.Join(home, "Videos"))
UserDirs.Templates = pathutil.EnvPath(userdirs.EnvTemplatesDir, dirs.Templates, filepath.Join(home, "Templates"))
UserDirs.PublicShare = pathutil.EnvPath(userdirs.EnvPublicShareDir, dirs.PublicShare, filepath.Join(home, "Public"))
UserDirs.Projects = pathutil.EnvPath(userdirs.EnvProjectsDir, dirs.Projects, filepath.Join(home, "Projects"))
}
11 changes: 11 additions & 0 deletions paths_unix_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,11 @@ func TestDefaultUserDirs(t *testing.T) {
expected: filepath.Join(home, "Public"),
actual: &xdg.UserDirs.PublicShare,
},
&envSample{
name: "XDG_PROJECTS_DIR",
expected: filepath.Join(home, "Projects"),
actual: &xdg.UserDirs.Projects,
},
)
}

Expand Down Expand Up @@ -239,6 +244,12 @@ func TestCustomUserDirs(t *testing.T) {
expected: filepath.Join(home, ".local/Public"),
actual: &xdg.UserDirs.PublicShare,
},
&envSample{
name: "XDG_PROJECTS_DIR",
value: "$HOME/.local/Projects",
expected: filepath.Join(home, ".local/Projects"),
actual: &xdg.UserDirs.Projects,
},
)
}

Expand Down
7 changes: 7 additions & 0 deletions paths_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ func initUserDirs(home string, kf *knownFolders) {
UserDirs.Videos = pathutil.EnvPath(userdirs.EnvVideosDir, kf.videos)
UserDirs.Templates = pathutil.EnvPath(userdirs.EnvTemplatesDir, kf.templates)
UserDirs.PublicShare = pathutil.EnvPath(userdirs.EnvPublicShareDir, kf.public)
UserDirs.Projects = pathutil.EnvPath(userdirs.EnvProjectsDir, kf.projects)
}

type knownFolders struct {
Expand All @@ -69,6 +70,7 @@ type knownFolders struct {
videos string
templates string
public string
projects string
fonts string
programs string
commonPrograms string
Expand Down Expand Up @@ -152,6 +154,11 @@ func initKnownFolders(home string) *knownFolders {
[]string{"PUBLIC"},
[]string{filepath.Join(kf.userProfiles, "Public")},
)
kf.projects = pathutil.KnownFolder(
nil,
nil,
[]string{filepath.Join(home, "Projects")},
)
kf.fonts = pathutil.KnownFolder(
windows.FOLDERID_Fonts,
nil,
Expand Down
11 changes: 11 additions & 0 deletions paths_windows_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,11 @@ func TestDefaultUserDirs(t *testing.T) {
expected: filepath.Join(`C:\`, "Users", "Public"),
actual: &xdg.UserDirs.PublicShare,
},
&envSample{
name: "XDG_PROJECTS_DIR",
expected: filepath.Join(home, "Projects"),
actual: &xdg.UserDirs.Projects,
},
)
}

Expand Down Expand Up @@ -269,5 +274,11 @@ func TestCustomUserDirs(t *testing.T) {
expected: filepath.Join(home, "Files/Public"),
actual: &xdg.UserDirs.PublicShare,
},
&envSample{
name: "XDG_PROJECTS_DIR",
value: filepath.Join(home, "Files/Projects"),
expected: filepath.Join(home, "Files/Projects"),
actual: &xdg.UserDirs.Projects,
},
)
}
Loading