Files
iris-context/root/config_cmd.go
T
VERSE d6cfb9c909 feat(config): add some more config options (#64)
## Add
Make these things configurable
- Expand aliases
- Suggest hidden files (#59)
- Toggle menu and mode 

```
[ui]
hidden-files = true # or false

[core]
expand-alias = true # or false

[keybindings]
toggle-mode = "ctrl+r"
toggle-menu = "ctrl+space"
```

- Auto reload config on changes: now just changes config and save the
file, IRIS will auto detect and reload in silent
- Added all these in config on init and docs

## Fix
I tested on holding backspace and the ghost text keep glitching so I
fixed it, this is just a small fix
2026-07-29 20:43:46 +07:00

124 lines
2.6 KiB
Go

package root
import (
"fmt"
"os"
"path/filepath"
"github.com/BurntSushi/toml"
"github.com/spf13/cobra"
"github.com/versenilvis/iris/internal/config"
)
var ConfigCmd = &cobra.Command{
Use: "config",
Short: "manage iris configuration",
}
var ConfigInitCmd = &cobra.Command{
Use: "init",
Short: "initialize default configuration file with comments",
Run: func(cmd *cobra.Command, args []string) {
path, err := config.ConfigPath()
if err != nil {
fmt.Printf("failed to get config path: %v\n", err)
return
}
if _, statErr := os.Stat(path); statErr == nil {
fmt.Printf("config file already exists at %s\n", path)
return
}
_ = os.MkdirAll(filepath.Dir(path), 0755)
defaultContent := `# ~/.config/iris/config.toml
# iris configuration file
[core]
# schema version
# do not edit this field manually
version = 1
# override shell: "bash", "zsh", "fish", keep empty for auto detection
shell = ""
# startup mode: "last", "spec", "history"
# "last" = remember last mode used
mode = "last"
# enable debug logging
debug = false
# auto expand alias when typing space
expand-alias = true
[ui]
# visual style: "modern" (icons, category pills, shortcut footer) or "classic" (minimalist, centered number, no icons)
style = "modern"
# enable Nerd Fonts icons in overlay menu
nerd-fonts = true
# enable inline ghost text
ghost-text = true
# show hidden files (starting with dot) in file generator
hidden-files = false
# maximum suggestions to display
max-suggestions = 100
# maximum height of the overlay
max-height = 15
[keybindings]
# toggle between spec and history mode
toggle-mode = "ctrl+r"
# toggle menu visibility
toggle-menu = "ctrl+space"
[git]
# hide current branch in checkout/switch list
filter-active-branch = true
# merge remote and local branches with same name
deduplicate-branches = true
[updater]
# check for updates on startup
check-on-startup = true
# update channel: "stable", "nightly"
channel = "stable"
# interval between update checks, e.g. "24h", "6h", "30m"
check-interval = "24h"
`
err = os.WriteFile(path, []byte(defaultContent), 0644)
if err != nil {
fmt.Printf("failed to write config file: %v\n", err)
return
}
fmt.Printf("initialized config file at %s\n", path)
},
}
var ConfigShowCmd = &cobra.Command{
Use: "show",
Short: "show the resolved configuration",
Run: func(cmd *cobra.Command, args []string) {
enc := toml.NewEncoder(cmd.OutOrStdout())
if err := enc.Encode(config.Get()); err != nil {
fmt.Fprintf(cmd.ErrOrStderr(), "failed to encode config: %v\n", err)
}
},
}
func init() {
ConfigCmd.AddCommand(ConfigInitCmd)
ConfigCmd.AddCommand(ConfigShowCmd)
rootCmd.AddCommand(ConfigCmd)
}