Skip to content

Instantly share code, notes, and snippets.

@algonzalez
Created July 15, 2024 16:29
Show Gist options
  • Save algonzalez/f8d4257d87f65d6a50511053d7e2fede to your computer and use it in GitHub Desktop.
Save algonzalez/f8d4257d87f65d6a50511053d7e2fede to your computer and use it in GitHub Desktop.
// https://go.dev/play/p/lrWohXeh1vG
// https://goplay.tools/snippet/lrWohXeh1vG
func getOsDefaultEditor() string {
switch runtime.GOOS {
case "darwin":
return "textedit"
case "linux", "freebsd", "netbsd", "openbsd":
return "vi"
case "windows":
return "notepad"
default:
return ""
}
}
func GetEnvDefinedEditorOrDefault(defaultWhenNotFound string) string {
ed := os.Getenv("EDITOR")
if len(ed) > 0 {
return ed
}
return defaultWhenNotFound
}
func GetEnvDefinedEditor() string {
return GetEnvDefinedEditorOrDefault(getOsDefaultEditor())
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment