Files
ghosttyconf/main.go
T
mikeandClaude Opus 5.5 e5750ef24b Version 1.0.0, release build script
- version.go/version.txt, --version flag, version in the help title
- build.sh builds static binaries for macOS and Linux into ./bin
- make build/install inject version.txt, make dist runs build.sh
- README: binary downloads; development docs: release process

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-22 13:29:39 +02:00

93 lines
2.4 KiB
Go

// Command ghosttyconf is a terminal editor for the Ghostty configuration.
package main
import (
"flag"
"fmt"
"os"
"path/filepath"
tea "github.com/charmbracelet/bubbletea"
"ghosttyconf/internal/config"
"ghosttyconf/internal/ghostty"
"ghosttyconf/internal/schema"
"ghosttyconf/internal/ui"
)
func main() {
configPath := flag.String("config", "", "config file to edit (default: Ghostty's default config file)")
ghosttyBin := flag.String("ghostty", "", "path to the ghostty binary (default: search $PATH and /Applications)")
offline := flag.Bool("offline", false, "do not run ghostty; use the built-in option list")
printPath := flag.Bool("print-path", false, "print the config file that would be edited and exit")
noReload := flag.Bool("no-reload", false, "do not ask Ghostty to reload its configuration after saving")
showVersion := flag.Bool("version", false, "print the version and exit")
flag.Usage = func() {
fmt.Fprintf(flag.CommandLine.Output(), "Usage: %s [flags] [config-file]\n\n", filepath.Base(os.Args[0]))
fmt.Fprintf(flag.CommandLine.Output(), "A terminal editor for the Ghostty configuration (version %s). Flags:\n", Version)
flag.PrintDefaults()
}
flag.Parse()
if *showVersion {
fmt.Println("ghosttyconf", Version)
return
}
if flag.NArg() > 1 {
flag.Usage()
os.Exit(2)
}
if flag.NArg() == 1 {
*configPath = flag.Arg(0)
}
path := *configPath
if path == "" {
path = ghostty.DefaultConfigPath()
}
if abs, err := filepath.Abs(path); err == nil {
path = abs
}
if *printPath {
fmt.Println(path)
return
}
if err := run(path, *ghosttyBin, *offline, !*noReload); err != nil {
fmt.Fprintln(os.Stderr, "ghosttyconf:", err)
os.Exit(1)
}
}
func run(path, ghosttyBin string, offline, autoReload bool) error {
sch, err := schema.Embedded()
if err != nil {
return err
}
var gh *ghostty.Ghostty
if !offline {
gh, err = ghostty.Find(ghosttyBin)
if err != nil && ghosttyBin != "" {
return err
}
if gh != nil {
if docs, err := gh.DefaultsWithDocs(); err == nil {
sch.Refresh(docs, gh.Version)
}
}
}
file, err := config.Load(path)
if err != nil {
return fmt.Errorf("read config: %w", err)
}
app := ui.New(sch, gh, file)
app.SetAutoReload(autoReload)
app.SetVersion(Version)
p := tea.NewProgram(app, tea.WithAltScreen(), tea.WithMouseCellMotion())
defer ui.RestoreTerminal()
_, err = p.Run()
return err
}