mirror of
https://github.com/cheat/cheat.git
synced 2024-12-18 10:45:05 +01:00
d598d96fce
Fix an issue whereby colorization would output ANSI codes if a pager was not configured. The solution here is to stop guessing about the state of the user's system at runtime, as well as the user's intention. The installer now chooses an appropriate installer when generating configs, and no longer bothers searching for pagers at runtime.
31 lines
627 B
Go
31 lines
627 B
Go
package config
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"os/exec"
|
|
"runtime"
|
|
)
|
|
|
|
// Editor attempts to locate an editor that's appropriate for the environment.
|
|
func Editor() (string, error) {
|
|
|
|
// default to `notepad.exe` on Windows
|
|
if runtime.GOOS == "windows" {
|
|
return "notepad", nil
|
|
}
|
|
|
|
// look for `nano` on the `PATH`
|
|
nano, _ := exec.LookPath("nano")
|
|
|
|
// search for `$VISUAL`, `$EDITOR`, and then `nano`, in that order
|
|
for _, editor := range []string{os.Getenv("VISUAL"), os.Getenv("EDITOR"), nano} {
|
|
if editor != "" {
|
|
return editor, nil
|
|
}
|
|
}
|
|
|
|
// return an error if no path is found
|
|
return "", fmt.Errorf("no editor set")
|
|
}
|