This commit is contained in:
Amir B. 2026-08-05 11:11:42 +08:00 committed by GitHub
commit 9c07022b3f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
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")