2024-03-11 20:23:36 -04:00
|
|
|
package env
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"runtime"
|
|
|
|
)
|
|
|
|
|
|
|
|
// GetEditor gets the configured editor by checking environmental
|
|
|
|
// variables EDITOR and VISUAL
|
|
|
|
func GetEditor() string {
|
|
|
|
var editor string
|
2024-05-29 16:05:36 -04:00
|
|
|
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 {
|
2024-03-14 12:47:19 -04:00
|
|
|
var tmp string
|
2024-03-11 20:23:36 -04:00
|
|
|
switch runtime.GOOS {
|
|
|
|
case "windows":
|
2024-03-14 12:47:19 -04:00
|
|
|
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":
|
2024-03-14 12:47:19 -04:00
|
|
|
tmp = "/tmp"
|
2024-03-11 20:23:36 -04:00
|
|
|
}
|
2024-03-14 12:47:19 -04:00
|
|
|
return tmp
|
2024-03-11 20:23:36 -04:00
|
|
|
}
|