Skip to content

Commit d89b17b

Browse files
Fix K9S_EDITOR
1 parent 420a533 commit d89b17b

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

internal/view/exec.go

+15-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ const (
3939
outputPrefix = "[output]"
4040
)
4141

42-
var editorEnvVars = []string{"KUBE_EDITOR", "K9S_EDITOR", "EDITOR"}
42+
var editorEnvVars = []string{"K9S_EDITOR", "KUBE_EDITOR", "EDITOR"}
4343

4444
type shellOpts struct {
4545
clear, background bool
@@ -181,6 +181,20 @@ func execute(opts shellOpts, statusChan chan<- string) error {
181181
cmds := make([]*exec.Cmd, 0, 1)
182182
cmd := exec.CommandContext(ctx, opts.binary, opts.args...)
183183
log.Debug().Msgf("RUNNING> %s", opts)
184+
185+
if env := os.Getenv("K9S_EDITOR"); env != "" {
186+
// There may be situations where the user sets the editor as the binary
187+
// followed by some arguments (e.g. "code -w" to make it work with vscode)
188+
//
189+
// In such cases, the actual binary is only the first token
190+
binTokens := strings.Split(env, " ")
191+
192+
if bin, err := exec.LookPath(binTokens[0]); err == nil {
193+
binTokens[0] = bin
194+
cmd.Env = append(os.Environ(), fmt.Sprintf("KUBE_EDITOR=%s", strings.Join(binTokens, " ")))
195+
}
196+
}
197+
184198
cmds = append(cmds, cmd)
185199

186200
for _, p := range opts.pipes {

0 commit comments

Comments
 (0)