mirror of
https://github.com/charmbracelet/glow
synced 2024-12-14 22:22:26 +00:00
8b5468468a
* fix: improve editor handling Signed-off-by: Carlos A Becker <caarlos0@users.noreply.github.com> * test: add tests Signed-off-by: Carlos A Becker <caarlos0@users.noreply.github.com> Signed-off-by: Carlos A Becker <caarlos0@users.noreply.github.com>
27 lines
534 B
Go
27 lines
534 B
Go
package editor
|
|
|
|
import (
|
|
"os"
|
|
"os/exec"
|
|
"strings"
|
|
)
|
|
|
|
const defaultEditor = "nano"
|
|
|
|
// Cmd returns a *exec.Cmd editing the given path with $EDITOR or nano if no
|
|
// $EDITOR is set.
|
|
func Cmd(path string) *exec.Cmd {
|
|
editor, args := getEditor()
|
|
return exec.Command(editor, append(args, path)...)
|
|
}
|
|
|
|
func getEditor() (string, []string) {
|
|
editor := strings.Fields(os.Getenv("EDITOR"))
|
|
if len(editor) > 1 {
|
|
return editor[0], editor[1:]
|
|
}
|
|
if len(editor) == 1 {
|
|
return editor[0], []string{}
|
|
}
|
|
return defaultEditor, []string{}
|
|
}
|