Skip to content

Commit

Permalink
Merge pull request #22 from daemonp/visual_editor_env
Browse files Browse the repository at this point in the history
Use $VISUAL and $EDITOR env vars for editor selection
  • Loading branch information
adzimzf authored Jun 24, 2024
2 parents 868c0ab + d82bea8 commit c5a57fa
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions editor/edit.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@ import (

const DefaultEditor = "nano"

// Edit edit the text using editor
// Edit the text using editor
func Edit(text string, tmpPattern string) (string, error) {

if tmpPattern == "" {
tmpPattern = "tpot_*.txt"
}
Expand All @@ -25,7 +24,15 @@ func Edit(text string, tmpPattern string) (string, error) {
return "", err
}

cmd := exec.Command(DefaultEditor, f.Name())
editor := os.Getenv("VISUAL")
if editor == "" {
editor = os.Getenv("EDITOR")
if editor == "" {
editor = DefaultEditor
}
}

cmd := exec.Command(editor, f.Name())
cmd.Stdin = os.Stdin
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
Expand Down

0 comments on commit c5a57fa

Please sign in to comment.