From 5f14914b7e698523145ee4a5031201f394947b0e Mon Sep 17 00:00:00 2001 From: Carlos Alexandro Becker Date: Tue, 25 Oct 2022 15:35:12 -0300 Subject: fix: editor with args (#364) * fix: editor with args Signed-off-by: Carlos A Becker * Update config_cmd.go Signed-off-by: Carlos A Becker --- config_cmd.go | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/config_cmd.go b/config_cmd.go index 22c3825..8ec0c4b 100644 --- a/config_cmd.go +++ b/config_cmd.go @@ -6,6 +6,7 @@ import ( "os" "os/exec" "path" + "strings" "path/filepath" "github.com/charmbracelet/charm/ui/common" @@ -32,8 +33,8 @@ var configCmd = &cobra.Command{ Example: formatBlock("glow config\nglow config --config path/to/config.yml"), Args: cobra.NoArgs, RunE: func(cmd *cobra.Command, args []string) error { - editor := os.Getenv("EDITOR") - if editor == "" { + editor := strings.Fields(os.Getenv("EDITOR")) + if len(editor) == 0 { return errors.New("no EDITOR environment variable set") } @@ -48,7 +49,7 @@ var configCmd = &cobra.Command{ } if ext := path.Ext(configFile); ext != ".yaml" && ext != ".yml" { - return fmt.Errorf("'%s' is not a supported config type: use '%s' or '%s'\n", ext, ".yaml", ".yml") + return fmt.Errorf("'%s' is not a supported config type: use '%s' or '%s'", ext, ".yaml", ".yml") } if _, err := os.Stat(configFile); os.IsNotExist(err) { @@ -62,7 +63,7 @@ var configCmd = &cobra.Command{ if err != nil { return err } - defer f.Close() + defer func() { _ = f.Close() }() if _, err := f.WriteString(defaultConfig); err != nil { return err @@ -71,7 +72,11 @@ var configCmd = &cobra.Command{ return err } - c := exec.Command(editor, configFile) + var eargs []string + if len(editor) > 1 { + eargs = editor[1:] + } + c := exec.Command(editor[0], append(eargs, configFile)...) // nolint: gosec c.Stdin = os.Stdin c.Stdout = os.Stdout c.Stderr = os.Stderr -- cgit v1.2.3