Add self-update, version 1.0.1
ghosttyconf --update installs the newest release from git.micw.org, --check-update only checks. The download lands next to the running binary, is started once with --version and only then replaces it. Once a day a normal start asks in the background and mentions a newer release in the header, at the top of the help and on stderr after quitting; only on a terminal and not with GHOSTTYCONF_NO_UPDATE_CHECK set. selfupdate.go is nscan's copyable template, with goca's --update spelling in the hints. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
e5750ef24b
commit
fb5602452a
13 files changed
+818
-11
No files matched your search
@@ -16,12 +16,21 @@ import (
|
||||
)
|
||||
|
||||
func main() {
|
||||
// The background look for a newer release (selfupdate.go). Taken before
|
||||
// the flags, so it can stay out of the help.
|
||||
if len(os.Args) == 2 && os.Args[1] == updateRefreshFlag {
|
||||
selfUpdate.refresh()
|
||||
return
|
||||
}
|
||||
|
||||
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")
|
||||
update := flag.Bool("update", false, "install the newest release in place of this binary and exit")
|
||||
checkUpdate := flag.Bool("check-update", false, "check for a newer release 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)
|
||||
@@ -32,6 +41,19 @@ func main() {
|
||||
fmt.Println("ghosttyconf", Version)
|
||||
return
|
||||
}
|
||||
if *update || *checkUpdate {
|
||||
var err error
|
||||
if *update {
|
||||
err = selfUpdate.install(os.Stdout)
|
||||
} else {
|
||||
err = selfUpdate.check(os.Stdout)
|
||||
}
|
||||
if err != nil {
|
||||
fmt.Fprintln(os.Stderr, "ghosttyconf:", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
return
|
||||
}
|
||||
if flag.NArg() > 1 {
|
||||
flag.Usage()
|
||||
os.Exit(2)
|
||||
@@ -85,6 +107,15 @@ func run(path, ghosttyBin string, offline, autoReload bool) error {
|
||||
app := ui.New(sch, gh, file)
|
||||
app.SetAutoReload(autoReload)
|
||||
app.SetVersion(Version)
|
||||
// Costs nothing: the hint comes from a note in the cache, and the asking
|
||||
// happens at most once a day, in the background.
|
||||
if hint := selfUpdate.daily(); hint != "" {
|
||||
app.SetUpdate(selfUpdate.loadState().Latest)
|
||||
// Once more after the editor has closed, where `ghosttyconf --update`
|
||||
// can be typed right away. Deferred before RestoreTerminal, so it
|
||||
// runs after it.
|
||||
defer fmt.Fprintln(os.Stderr, hint)
|
||||
}
|
||||
p := tea.NewProgram(app, tea.WithAltScreen(), tea.WithMouseCellMotion())
|
||||
defer ui.RestoreTerminal()
|
||||
_, err = p.Run()
|
||||
|
||||
Reference in new issue
Block a user