From 951163d41868a394a35a50d198fed0bc447e8018 Mon Sep 17 00:00:00 2001 From: plgruener Date: Wed, 5 May 2021 03:31:11 +0200 Subject: [PATCH 1/2] support $VISUAL, prefer it over $EDITOR Currently, `tea` only supports the $EDITOR env var to open the user's preferred editor (used for reviewing pull requests). Standard *nix practice is, however, to check for $VISUAL first and only use $EDITOR as fallback. This is also done by Git itself, see man git-var(1). (Actually, the order is $GIT_EDITOR > core.editor > $VISUAL > $EDITOR > vi) --- modules/interact/pull_review.go | 2 +- modules/task/pull_review.go | 9 ++++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/modules/interact/pull_review.go b/modules/interact/pull_review.go index 7a190ef..1052dcd 100644 --- a/modules/interact/pull_review.go +++ b/modules/interact/pull_review.go @@ -63,7 +63,7 @@ func ReviewPull(ctx *context.TeaContext, idx int64) error { return task.CreatePullReview(ctx, idx, state, comment, codeComments) } -// DoDiffReview (1) fetches & saves diff in tempfile, (2) starts $EDITOR to comment on diff, +// DoDiffReview (1) fetches & saves diff in tempfile, (2) starts $VISUAL or $EDITOR to comment on diff, // (3) parses resulting file into code comments. func DoDiffReview(ctx *context.TeaContext, idx int64) ([]gitea.CreatePullReviewComment, error) { tmpFile, err := task.SavePullDiff(ctx, idx) diff --git a/modules/task/pull_review.go b/modules/task/pull_review.go index 1cef147..1a746e7 100644 --- a/modules/task/pull_review.go +++ b/modules/task/pull_review.go @@ -107,10 +107,13 @@ func ParseDiffComments(diffFile string) ([]gitea.CreatePullReviewComment, error) // OpenFileInEditor opens filename in a text editor, and blocks until the editor terminates. func OpenFileInEditor(filename string) error { - editor := os.Getenv("EDITOR") + editor := os.Getenv("VISUAL") if editor == "" { - fmt.Println("No $EDITOR env is set, defaulting to vim") - editor = "vim" + editor = os.Getenv("EDITOR") + if editor == "" { + fmt.Println("No $VISUAL or $EDITOR env is set, defaulting to vim") + editor = "vim" + } } // Get the full executable path for the editor. -- 2.40.1 From e709df62597d0bdd8ec037c2a8785e27e01da8c7 Mon Sep 17 00:00:00 2001 From: plgruener Date: Wed, 5 May 2021 15:06:57 +0200 Subject: [PATCH 2/2] change default text editor to `vi` --- modules/task/pull_review.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/task/pull_review.go b/modules/task/pull_review.go index 1a746e7..ff3bd08 100644 --- a/modules/task/pull_review.go +++ b/modules/task/pull_review.go @@ -112,7 +112,7 @@ func OpenFileInEditor(filename string) error { editor = os.Getenv("EDITOR") if editor == "" { fmt.Println("No $VISUAL or $EDITOR env is set, defaulting to vim") - editor = "vim" + editor = "vi" } } -- 2.40.1