diff --git a/config_cmd.go b/config_cmd.go index 390a1db..33e4b1d 100644 --- a/config_cmd.go +++ b/config_cmd.go @@ -23,13 +23,16 @@ pager: false width: 80 # show all files, including hidden and ignored. all: false +# editor used to open files (defaults to $EDITOR, or "nano" if unset). +# Accepts an editor name or a command with flags, e.g. "code --wait". +editor: "" ` var configCmd = &cobra.Command{ Use: "config", Hidden: false, Short: "Edit the glow config file", - Long: paragraph(fmt.Sprintf("\n%s the glow config file. We’ll use EDITOR to determine which editor to use. If the config file doesn't exist, it will be created.", keyword("Edit"))), + Long: paragraph(fmt.Sprintf("\n%s the glow config file. The editor is chosen from the `editor` config key, falling back to $EDITOR (and finally nano) if unset. If the config file doesn't exist, it will be created.", keyword("Edit"))), Example: paragraph("glow config\nglow config --config path/to/config.yml"), Args: cobra.NoArgs, RunE: func(*cobra.Command, []string) error { diff --git a/main.go b/main.go index b31ca15..caf89b2 100644 --- a/main.go +++ b/main.go @@ -44,6 +44,7 @@ var ( showLineNumbers bool preserveNewLines bool mouse bool + editorOverride string rootCmd = &cobra.Command{ Use: "glow [SOURCE|DIR]", @@ -173,6 +174,15 @@ func validateOptions(cmd *cobra.Command) error { showAllFiles = viper.GetBool("all") preserveNewLines = viper.GetBool("preserveNewLines") showLineNumbers = viper.GetBool("showLineNumbers") + editorOverride = viper.GetString("editor") + + // Apply the configured editor to this process so the embedded x/editor + // package (used by `glow config` and the in-TUI editor key) picks it up. + // The override only affects this glow invocation and does not leak into + // the user's shell environment. + if editorOverride != "" { + _ = os.Setenv("EDITOR", editorOverride) + } if pager && tui { return errors.New("cannot use both pager and tui")