@@ -18,25 +18,34 @@ import (
1818)
1919
2020var (
21- bom = []byte {0xef , 0xbb , 0xbf }
22- editor = "nano" // EXTENDED to switch from vim as a default editor
21+ bom = []byte {0xef , 0xbb , 0xbf }
22+ defaultEditor = "nano" // EXTENDED to switch from vim as a default editor
2323)
2424
2525func init () {
2626 if runtime .GOOS == "windows" {
27- editor = "notepad"
27+ defaultEditor = "notepad"
2828 } else if g := os .Getenv ("GIT_EDITOR" ); g != "" {
29- editor = g
29+ defaultEditor = g
3030 } else if v := os .Getenv ("VISUAL" ); v != "" {
31- editor = v
31+ defaultEditor = v
3232 } else if e := os .Getenv ("EDITOR" ); e != "" {
33- editor = e
33+ defaultEditor = e
3434 }
3535}
3636
3737// EXTENDED to enable different prompting behavior
3838type GhEditor struct {
3939 * survey.Editor
40+ EditorCommand string
41+ }
42+
43+ func (e * GhEditor ) editorCommand () string {
44+ if e .EditorCommand == "" {
45+ return defaultEditor
46+ }
47+
48+ return e .EditorCommand
4049}
4150
4251// EXTENDED to change prompt text
@@ -49,17 +58,17 @@ var EditorQuestionTemplate = `
4958{{- else }}
5059 {{- if and .Help (not .ShowHelp)}}{{color "cyan"}}[{{ .Config.HelpInput }} for help]{{color "reset"}} {{end}}
5160 {{- if and .Default (not .HideDefault)}}{{color "white"}}({{.Default}}) {{color "reset"}}{{end}}
52- {{- color "cyan"}}[(e) to launch {{ .EditorName }}, enter to skip] {{color "reset"}}
61+ {{- color "cyan"}}[(e) to launch {{ .EditorCommand }}, enter to skip] {{color "reset"}}
5362{{- end}}`
5463
5564// EXTENDED to pass editor name (to use in prompt)
5665type EditorTemplateData struct {
5766 survey.Editor
58- EditorName string
59- Answer string
60- ShowAnswer bool
61- ShowHelp bool
62- Config * survey.PromptConfig
67+ EditorCommand string
68+ Answer string
69+ ShowAnswer bool
70+ ShowHelp bool
71+ Config * survey.PromptConfig
6372}
6473
6574// EXTENDED to augment prompt text and keypress handling
@@ -68,9 +77,9 @@ func (e *GhEditor) prompt(initialValue string, config *survey.PromptConfig) (int
6877 EditorQuestionTemplate ,
6978 // EXTENDED to support printing editor in prompt
7079 EditorTemplateData {
71- Editor : * e .Editor ,
72- EditorName : filepath .Base (editor ),
73- Config : config ,
80+ Editor : * e .Editor ,
81+ EditorCommand : filepath .Base (e . editorCommand () ),
82+ Config : config ,
7483 },
7584 )
7685 if err != nil {
@@ -109,10 +118,10 @@ func (e *GhEditor) prompt(initialValue string, config *survey.PromptConfig) (int
109118 EditorQuestionTemplate ,
110119 EditorTemplateData {
111120 // EXTENDED to support printing editor in prompt
112- Editor : * e .Editor ,
113- EditorName : filepath .Base (editor ),
114- ShowHelp : true ,
115- Config : config ,
121+ Editor : * e .Editor ,
122+ EditorCommand : filepath .Base (e . editorCommand () ),
123+ ShowHelp : true ,
124+ Config : config ,
116125 },
117126 )
118127 if err != nil {
@@ -155,7 +164,7 @@ func (e *GhEditor) prompt(initialValue string, config *survey.PromptConfig) (int
155164
156165 stdio := e .Stdio ()
157166
158- args , err := shellquote .Split (editor )
167+ args , err := shellquote .Split (e . editorCommand () )
159168 if err != nil {
160169 return "" , err
161170 }
0 commit comments