summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCarlos Alexandro Becker <caarlos0@users.noreply.github.com>2022-10-25 15:35:12 -0300
committerGitHub <noreply@github.com>2022-10-25 15:35:12 -0300
commit5f14914b7e698523145ee4a5031201f394947b0e (patch)
tree975a086b4e5cb0996adf77d77e0f2b0178f95ebc
parent44b078e44a45e79f88bb0d904ba4ea05eb278104 (diff)
fix: editor with args (#364)
* fix: editor with args Signed-off-by: Carlos A Becker <caarlos0@users.noreply.github.com> * Update config_cmd.go Signed-off-by: Carlos A Becker <caarlos0@users.noreply.github.com>
-rw-r--r--config_cmd.go15
1 files 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