Skip to content

Commit

Permalink
Merge pull request #15 from jarojasm95/issue-14-KUBE_EDITOR
Browse files Browse the repository at this point in the history
Default to KUBE_EDITOR and keep EDITOR as fallback
  • Loading branch information
rajatjindal authored Aug 16, 2021
2 parents eceaa75 + 218cede commit d4b3edf
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions pkg/editor/editor.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,22 @@ import (

const defaultEditor = "vi"

func getEditor() string {
if os.Getenv("KUBE_EDITOR") != "" {
return os.Getenv("KUBE_EDITOR")
}

if os.Getenv("EDITOR") != "" {
return os.Getenv("EDITOR")
}

return defaultEditor
}

//Edit opens the editor
func Edit(file string) error {
editorFromEnv := os.Getenv("EDITOR")
if editorFromEnv == "" {
editorFromEnv = defaultEditor
}

command, args := getCommandAndArgs(editorFromEnv, file)
command, args := getCommandAndArgs(getEditor(), file)

cmd := exec.Command(command, args...)
cmd.Stdin = os.Stdin
Expand Down

0 comments on commit d4b3edf

Please sign in to comment.