MCPcopy
hub / github.com/cheat/cheat / Editor

Function Editor

internal/config/editor.go:11–41  ·  view source on GitHub ↗

Editor attempts to locate an editor that's appropriate for the environment.

()

Source from the content-addressed store, hash-verified

9
10// Editor attempts to locate an editor that's appropriate for the environment.
11func Editor() (string, error) {
12
13 // default to `notepad.exe` on Windows
14 if runtime.GOOS == "windows" {
15 return "notepad", nil
16 }
17
18 // look for `nano` and `vim` on the `PATH`
19 def, _ := exec.LookPath("editor") // default `editor` wrapper
20 nano, _ := exec.LookPath("nano")
21 vim, _ := exec.LookPath("vim")
22
23 // set editor priority
24 editors := []string{
25 os.Getenv("VISUAL"),
26 os.Getenv("EDITOR"),
27 def,
28 nano,
29 vim,
30 }
31
32 // return the first editor that was found per the priority above
33 for _, editor := range editors {
34 if editor != "" {
35 return editor, nil
36 }
37 }
38
39 // return an error if no path is found
40 return "", fmt.Errorf("no editor set")
41}

Callers 3

ExpandTemplateFunction · 0.92
NewFunction · 0.85
TestEditorFunction · 0.85

Calls

no outgoing calls

Tested by 1

TestEditorFunction · 0.68