agedit/pkg/env/env.go

48 lines
883 B
Go
Raw Permalink Normal View History

2024-03-11 20:23:36 -04:00
package env
import (
"os"
"regexp"
"runtime"
"strings"
)
// GetEditor gets the configured editor by checking environmental
// variables EDITOR and VISUAL
func GetEditor() string {
var editor string
if v, ok := os.LookupEnv("EDITOR"); ok {
editor = v
} else if v, ok := os.LookupEnv("VISUAL"); ok {
editor = v
2024-03-11 20:23:36 -04:00
} /* else {
// TODO: maybe pick something based on the OS
} */
return editor
}
// GetTempDirectory returns the systems temporary directory
//
// returns %TEMP% on Windows, /tmp on UNIX-like systems
func GetTempDirectory() string {
var tmp string
2024-03-11 20:23:36 -04:00
switch runtime.GOOS {
case "windows":
tmp = os.Getenv("TEMP")
case "android":
if t := os.Getenv("TMPDIR"); t != "" {
tmp = t
} else if t = os.Getenv("PREFIX"); t != "" {
tmp = t + "/tmp"
}
2024-03-11 20:23:36 -04:00
default:
fallthrough
case "darwin":
fallthrough
case "linux":
tmp = "/tmp"
2024-03-11 20:23:36 -04:00
}
return tmp
2024-03-11 20:23:36 -04:00
}