feat: allow choosing editor in configuration file

Adds an `editor` key to glow.yml so users can pick the editor used by
`glow config` and the in-TUI 'e' key without having to override $EDITOR
globally. Useful for cases like preferring `micro` for markdown while
keeping `vim` as the system default.

When set, the value is applied to glow's own process environment before
the embedded `charmbracelet/x/editor` package is invoked, so the existing
$EDITOR / nano fallback chain remains intact when the key is empty or
absent. The override does not leak into the user's shell.

Closes #944
This commit is contained in:
Metbcy 2026-05-23 23:00:31 +00:00
commit ece9be43b4
No known key found for this signature in database
2 changed files with 14 additions and 1 deletions

View file

@ -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. Well 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 {

10
main.go
View file

@ -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")