directories/user/user.go

161 lines
3.3 KiB
Go

package user
import (
"errors"
"os"
"runtime"
"git.martyn.berlin/martyn/directories/base"
)
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":
return windowsAudio()
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":
return windowsDesktop()
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":
return windowsDocuments()
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":
return windowsDownloads()
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":
return windowsPictures()
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":
return windowsPublic()
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":
return windowsTemplates()
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":
return windowsVideos()
case "darwin":
h, err := Home()
return h + "/Videos", err
}
return "", errors.New("could not determine location for Videos()")
}