diff --git a/README.md b/README.md index 564d3d6..c380883 100644 --- a/README.md +++ b/README.md @@ -128,6 +128,7 @@ as shown in the following tables. | XDG_VIDEOS_DIR | ~/Videos | ~/Movies | $home/videos | | XDG_TEMPLATES_DIR | ~/Templates | ~/Templates | $home/templates | | XDG_PUBLICSHARE_DIR | ~/Public | ~/Public | $home/public | +| XDG_PROJECTS_DIR | ~/Projects | ~/Projects | $home/projects | @@ -145,6 +146,7 @@ as shown in the following tables. | XDG_VIDEOS_DIR | Videos | %USERPROFILE%\Videos | | XDG_TEMPLATES_DIR | Templates | %APPDATA%\Microsoft\Windows\Templates | | XDG_PUBLICSHARE_DIR | Public | %PUBLIC% | +| XDG_PROJECTS_DIR | - | %USERPROFILE%\Projects | @@ -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) } ``` diff --git a/doc.go b/doc.go index 22ba478..5693998 100644 --- a/doc.go +++ b/doc.go @@ -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 diff --git a/internal/userdirs/config_unix.go b/internal/userdirs/config_unix.go index e0eda2f..3307216 100644 --- a/internal/userdirs/config_unix.go +++ b/internal/userdirs/config_unix.go @@ -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) diff --git a/internal/userdirs/config_unix_test.go b/internal/userdirs/config_unix_test.go index 3c52cae..7247421 100644 --- a/internal/userdirs/config_unix_test.go +++ b/internal/userdirs/config_unix_test.go @@ -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" @@ -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") diff --git a/internal/userdirs/userdirs.go b/internal/userdirs/userdirs.go index b3c30cf..a327624 100644 --- a/internal/userdirs/userdirs.go +++ b/internal/userdirs/userdirs.go @@ -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. @@ -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 } diff --git a/paths_darwin.go b/paths_darwin.go index 3b3d05f..15abd56 100644 --- a/paths_darwin.go +++ b/paths_darwin.go @@ -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")) } diff --git a/paths_darwin_test.go b/paths_darwin_test.go index 6be5046..3d5bd20 100644 --- a/paths_darwin_test.go +++ b/paths_darwin_test.go @@ -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, + }, ) } @@ -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, + }, ) } diff --git a/paths_plan9.go b/paths_plan9.go index d0c36ba..bbf2887 100644 --- a/paths_plan9.go +++ b/paths_plan9.go @@ -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")) } diff --git a/paths_plan9_test.go b/paths_plan9_test.go index 7ee3700..d639884 100644 --- a/paths_plan9_test.go +++ b/paths_plan9_test.go @@ -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, + }, ) } @@ -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, + }, ) } diff --git a/paths_unix.go b/paths_unix.go index 8a07809..697e8b6 100644 --- a/paths_unix.go +++ b/paths_unix.go @@ -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")) } diff --git a/paths_unix_test.go b/paths_unix_test.go index 38c44b1..8cd2bbb 100644 --- a/paths_unix_test.go +++ b/paths_unix_test.go @@ -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, + }, ) } @@ -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, + }, ) } diff --git a/paths_windows.go b/paths_windows.go index bb80819..d85c900 100644 --- a/paths_windows.go +++ b/paths_windows.go @@ -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 { @@ -69,6 +70,7 @@ type knownFolders struct { videos string templates string public string + projects string fonts string programs string commonPrograms string @@ -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, diff --git a/paths_windows_test.go b/paths_windows_test.go index 9c64455..c5ed8e9 100644 --- a/paths_windows_test.go +++ b/paths_windows_test.go @@ -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, + }, ) } @@ -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, + }, ) }