Skip to content

Commit

Permalink
Read user directories config file on Unix
Browse files Browse the repository at this point in the history
  • Loading branch information
adrg committed Jul 5, 2024
1 parent 9ec49fc commit 0f015c0
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions paths_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@ import (
"strconv"

"github.com/adrg/xdg/internal/pathutil"
"github.com/adrg/xdg/internal/userdirs"
)

func initDirs(home string) {
initBaseDirs(home)
initUserDirs(home)
initUserDirs(home, baseDirs.configHome)
}

func initBaseDirs(home string) {
Expand Down Expand Up @@ -50,13 +51,18 @@ func initBaseDirs(home string) {
baseDirs.fonts = pathutil.Unique(fontDirs)
}

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"))
func initUserDirs(home, configHome string) {
userDirsMap := userdirs.ParseConfigFile(filepath.Join(configHome, "user-dirs.dirs"))
if userDirsMap == nil {
userDirsMap = map[string]string{}
}

UserDirs.Desktop = xdgPath(envDesktopDir, userDirsMap[envDesktopDir], filepath.Join(home, "Desktop"))
UserDirs.Download = xdgPath(envDownloadDir, userDirsMap[envDownloadDir], filepath.Join(home, "Downloads"))
UserDirs.Documents = xdgPath(envDocumentsDir, userDirsMap[envDocumentsDir], filepath.Join(home, "Documents"))
UserDirs.Music = xdgPath(envMusicDir, userDirsMap[envMusicDir], filepath.Join(home, "Music"))
UserDirs.Pictures = xdgPath(envPicturesDir, userDirsMap[envPicturesDir], filepath.Join(home, "Pictures"))
UserDirs.Videos = xdgPath(envVideosDir, userDirsMap[envVideosDir], filepath.Join(home, "Videos"))
UserDirs.Templates = xdgPath(envTemplatesDir, userDirsMap[envTemplatesDir], filepath.Join(home, "Templates"))
UserDirs.PublicShare = xdgPath(envPublicShareDir, userDirsMap[envPublicShareDir], filepath.Join(home, "Public"))
}

0 comments on commit 0f015c0

Please sign in to comment.