@@ -39,7 +39,7 @@ const (
39
39
outputPrefix = "[output]"
40
40
)
41
41
42
- var editorEnvVars = []string {"KUBE_EDITOR " , "K9S_EDITOR " , "EDITOR" }
42
+ var editorEnvVars = []string {"K9S_EDITOR " , "KUBE_EDITOR " , "EDITOR" }
43
43
44
44
type shellOpts struct {
45
45
clear , background bool
@@ -130,7 +130,22 @@ func edit(a *App, opts shellOpts) bool {
130
130
if env == "" {
131
131
continue
132
132
}
133
- if bin , err = exec .LookPath (env ); err == nil {
133
+
134
+ // There may be situations where the user sets the editor as the binary
135
+ // followed by some arguments (e.g. "code -w" to make it work with vscode)
136
+ //
137
+ // In such cases, the actual binary is only the first token
138
+ envTokens := strings .Split (env , " " )
139
+
140
+ if bin , err = exec .LookPath (envTokens [0 ]); err == nil {
141
+ // Make sure the path is at the end (this allows running editors
142
+ // with custom options)
143
+ if len (envTokens ) > 1 {
144
+ originalArgs := opts .args
145
+ opts .args = envTokens [1 :]
146
+ opts .args = append (opts .args , originalArgs ... )
147
+ }
148
+
134
149
break
135
150
}
136
151
}
@@ -181,6 +196,20 @@ func execute(opts shellOpts, statusChan chan<- string) error {
181
196
cmds := make ([]* exec.Cmd , 0 , 1 )
182
197
cmd := exec .CommandContext (ctx , opts .binary , opts .args ... )
183
198
log .Debug ().Msgf ("RUNNING> %s" , opts )
199
+
200
+ if env := os .Getenv ("K9S_EDITOR" ); env != "" {
201
+ // There may be situations where the user sets the editor as the binary
202
+ // followed by some arguments (e.g. "code -w" to make it work with vscode)
203
+ //
204
+ // In such cases, the actual binary is only the first token
205
+ binTokens := strings .Split (env , " " )
206
+
207
+ if bin , err := exec .LookPath (binTokens [0 ]); err == nil {
208
+ binTokens [0 ] = bin
209
+ cmd .Env = append (os .Environ (), fmt .Sprintf ("KUBE_EDITOR=%s" , strings .Join (binTokens , " " )))
210
+ }
211
+ }
212
+
184
213
cmds = append (cmds , cmd )
185
214
186
215
for _ , p := range opts .pipes {
0 commit comments