2021-12-29 12:00:51 +00:00
|
|
|
package user
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
"os"
|
|
|
|
"runtime"
|
|
|
|
|
2021-12-29 21:44:28 +00:00
|
|
|
"git.martyn.berlin/martyn/directories/base"
|
2021-12-29 12:00:51 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func Home() (string, error) {
|
|
|
|
return base.Home()
|
|
|
|
}
|
|
|
|
|
|
|
|
func Audio() (string, error) {
|
|
|
|
switch runtime.GOOS {
|
|
|
|
case "linux":
|
|
|
|
e, ok := os.LookupEnv("XDG_MUSIC_DIR")
|
|
|
|
if ok {
|
|
|
|
return e, nil
|
|
|
|
}
|
|
|
|
case "windows":
|
2021-12-29 23:19:40 +00:00
|
|
|
return windowsAudio()
|
2021-12-29 12:00:51 +00:00
|
|
|
case "darwin":
|
|
|
|
h, err := Home()
|
|
|
|
return h + "/Music", err
|
|
|
|
}
|
|
|
|
return "", errors.New("could not determine location for Audio()")
|
|
|
|
}
|
|
|
|
|
|
|
|
func Desktop() (string, error) {
|
|
|
|
switch runtime.GOOS {
|
|
|
|
case "linux":
|
|
|
|
e, ok := os.LookupEnv("XDG_DESKTOP_DIR")
|
|
|
|
if ok {
|
|
|
|
return e, nil
|
|
|
|
}
|
|
|
|
case "windows":
|
2021-12-29 23:19:40 +00:00
|
|
|
return windowsDesktop()
|
2021-12-29 12:00:51 +00:00
|
|
|
case "darwin":
|
|
|
|
h, err := Home()
|
|
|
|
return h + "/Desktop", err
|
|
|
|
}
|
|
|
|
return "", errors.New("could not determine location for Desktop()")
|
|
|
|
}
|
|
|
|
|
|
|
|
func Documents() (string, error) {
|
|
|
|
switch runtime.GOOS {
|
|
|
|
case "linux":
|
|
|
|
e, ok := os.LookupEnv("XDG_DOCUMENTS_DIR")
|
|
|
|
if ok {
|
|
|
|
return e, nil
|
|
|
|
}
|
|
|
|
case "windows":
|
2021-12-29 23:19:40 +00:00
|
|
|
return windowsDocuments()
|
2021-12-29 12:00:51 +00:00
|
|
|
case "darwin":
|
|
|
|
h, err := Home()
|
|
|
|
return h + "/Documents", err
|
|
|
|
}
|
|
|
|
return "", errors.New("could not determine location for Documents()")
|
|
|
|
}
|
|
|
|
|
|
|
|
func Downloads() (string, error) {
|
|
|
|
switch runtime.GOOS {
|
|
|
|
case "linux":
|
|
|
|
e, ok := os.LookupEnv("XDG_DOWNLOAD_DIR")
|
|
|
|
if ok {
|
|
|
|
return e, nil
|
|
|
|
}
|
|
|
|
case "windows":
|
2021-12-29 23:19:40 +00:00
|
|
|
return windowsDownloads()
|
2021-12-29 12:00:51 +00:00
|
|
|
case "darwin":
|
|
|
|
h, err := Home()
|
|
|
|
return h + "/Downloads", err
|
|
|
|
}
|
|
|
|
return "", errors.New("could not determine location for Downloads()")
|
|
|
|
}
|
|
|
|
|
|
|
|
func Fonts() (string, error) {
|
|
|
|
switch runtime.GOOS {
|
|
|
|
case "linux":
|
|
|
|
e, ok := os.LookupEnv("XDG_DATA_HOME" + "/fonts")
|
|
|
|
if ok {
|
|
|
|
return e, nil
|
|
|
|
} else {
|
|
|
|
h, err := Home()
|
|
|
|
return h + "/.local/share/fonts", err
|
|
|
|
}
|
|
|
|
case "windows":
|
|
|
|
return "", errors.New("windows has no per-user fonts dir")
|
|
|
|
case "darwin":
|
|
|
|
h, err := Home()
|
|
|
|
return h + "/Library/Fonts", err
|
|
|
|
}
|
|
|
|
return "", errors.New("could not determine location for Fonts()")
|
|
|
|
}
|
|
|
|
|
|
|
|
func Pictures() (string, error) {
|
|
|
|
switch runtime.GOOS {
|
|
|
|
case "linux":
|
|
|
|
e, ok := os.LookupEnv("XDG_PICTURES_DIR")
|
|
|
|
if ok {
|
|
|
|
return e, nil
|
|
|
|
}
|
|
|
|
case "windows":
|
2021-12-29 23:19:40 +00:00
|
|
|
return windowsPictures()
|
2021-12-29 12:00:51 +00:00
|
|
|
case "darwin":
|
|
|
|
h, err := Home()
|
|
|
|
return h + "/Pictures", err
|
|
|
|
}
|
|
|
|
return "", errors.New("could not determine location for Pictures()")
|
|
|
|
}
|
|
|
|
|
|
|
|
func Public() (string, error) {
|
|
|
|
switch runtime.GOOS {
|
|
|
|
case "linux":
|
|
|
|
e, ok := os.LookupEnv("XDG_PUBLICSHARE_DIR")
|
|
|
|
if ok {
|
|
|
|
return e, nil
|
|
|
|
}
|
|
|
|
case "windows":
|
2021-12-29 23:19:40 +00:00
|
|
|
return windowsPublic()
|
2021-12-29 12:00:51 +00:00
|
|
|
case "darwin":
|
|
|
|
h, err := Home()
|
|
|
|
return h + "/Public", err
|
|
|
|
}
|
|
|
|
return "", errors.New("could not determine location for Public()")
|
|
|
|
}
|
|
|
|
|
|
|
|
func Templates() (string, error) {
|
|
|
|
switch runtime.GOOS {
|
|
|
|
case "linux":
|
|
|
|
e, ok := os.LookupEnv("XDG_TEMPLATES_DIR")
|
|
|
|
if ok {
|
|
|
|
return e, nil
|
|
|
|
}
|
|
|
|
case "windows":
|
2021-12-29 23:19:40 +00:00
|
|
|
return windowsTemplates()
|
2021-12-29 12:00:51 +00:00
|
|
|
case "darwin":
|
|
|
|
h, err := Home()
|
|
|
|
return h + "/Templates", err
|
|
|
|
}
|
|
|
|
return "", errors.New("could not determine location for Templates()")
|
|
|
|
}
|
|
|
|
|
|
|
|
func Videos() (string, error) {
|
|
|
|
switch runtime.GOOS {
|
|
|
|
case "linux":
|
|
|
|
e, ok := os.LookupEnv("XDG_VIDEOS_DIR")
|
|
|
|
if ok {
|
|
|
|
return e, nil
|
|
|
|
}
|
|
|
|
case "windows":
|
2021-12-29 23:19:40 +00:00
|
|
|
return windowsVideos()
|
2021-12-29 12:00:51 +00:00
|
|
|
case "darwin":
|
|
|
|
h, err := Home()
|
|
|
|
return h + "/Videos", err
|
|
|
|
}
|
|
|
|
return "", errors.New("could not determine location for Videos()")
|
|
|
|
}
|