Created
July 15, 2024 16:29
-
-
Save algonzalez/f8d4257d87f65d6a50511053d7e2fede to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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