Skip to content

Commit

Permalink
edit.go: Add core.editor for default editor
Browse files Browse the repository at this point in the history
The editor can also be set with the output of 'git config --get
core.editor'.  Use that if $GIT_EDITOR is not set.

Add core.editor as an additional option to pick the default editor.

Signed-off-by: Prarit Bhargava <[email protected]>
  • Loading branch information
prarit committed Mar 21, 2021
1 parent 78a28ab commit 7e9c436
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions internal/git/edit.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,21 @@ func EditFile(filePrefix, message string) (string, error) {
func editorPath() (string, error) {
cmd := New("var", "GIT_EDITOR")
cmd.Stdout = nil
e, err := cmd.Output()
a, err := cmd.Output()
if err != nil {
return "", err
}
return strings.TrimSpace(string(e)), nil
editor := strings.TrimSpace(string(a))
if editor == "" {
cmd = New("config", "--get", "core.editor")
cmd.Stdout = nil
b, err := cmd.Output()
if err != nil {
return "", err
}
editor = strings.TrimSpace(string(b))
}
return editor, nil
}

func editorCMD(editorPath, filePath string) *exec.Cmd {
Expand Down

0 comments on commit 7e9c436

Please sign in to comment.