mirror of
https://github.com/charmbracelet/glow.git
synced 2026-08-21 07:34:18 +02:00
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:
parent
53788271b3
commit
ece9be43b4
2 changed files with 14 additions and 1 deletions
|
|
@ -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 {
|
||||
|
|
|
|||
10
main.go
10
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")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue