diff --git a/Makefile b/Makefile
index 39a08b2..f0f0d87 100644
--- a/Makefile
+++ b/Makefile
@@ -1,12 +1,14 @@
BIN := ghosttyconf
+VERSION := $(shell cat version.txt)
+LDFLAGS := -X main.Version=$(VERSION)
-.PHONY: build install test schema screenshots clean
+.PHONY: build install test schema screenshots dist clean
build:
- go build -o $(BIN) .
+ go build -ldflags "$(LDFLAGS)" -o $(BIN) .
install:
- go install .
+ go install -ldflags "$(LDFLAGS)" .
test:
go test ./...
@@ -20,5 +22,9 @@ schema:
screenshots:
./tools/screenshots.sh
+# Release binaries for all platforms into ./bin (see build.sh).
+dist:
+ ./build.sh
+
clean:
- rm -f $(BIN)
+ rm -rf $(BIN) bin
diff --git a/README.md b/README.md
index 289d136..b1b1c53 100644
--- a/README.md
+++ b/README.md
@@ -6,6 +6,7 @@
+
@@ -47,7 +48,26 @@ stay intact, and after saving, Ghostty reloads the configuration right away.
## ๐ Installation
-You need [Go](https://go.dev/dl/) 1.24 or newer and Ghostty.
+### Download a binary
+
+Every [release](https://git.micw.org/mike/ghosttyconf/releases) has
+ready-to-run binaries for macOS and Linux (arm64 and amd64). They need nothing
+but Ghostty.
+
+```sh
+# macOS on Apple silicon; for other systems, replace darwin-arm64 with
+# darwin-amd64, linux-amd64 or linux-arm64
+curl -fLo ghosttyconf https://git.micw.org/mike/ghosttyconf/releases/download/1.0.0/ghosttyconf-darwin-arm64
+chmod +x ghosttyconf
+mv ghosttyconf ~/bin/ # or any other directory in your $PATH
+```
+
+If you download the binary with a browser, macOS blocks it at first. Remove
+the quarantine flag with `xattr -d com.apple.quarantine ghosttyconf`.
+
+### Build from source
+
+You need [Go](https://go.dev/dl/) 1.24 or newer.
```sh
git clone https://git.micw.org/mike/ghosttyconf.git
@@ -179,6 +199,7 @@ ghosttyconf [flags] [config-file]
--no-reload do not reload Ghostty after saving
--offline do not run ghostty; use the built-in option list
--print-path print the config file that would be edited and exit
+ --version print the version and exit
```
## ๐ง How it works
diff --git a/build.sh b/build.sh
new file mode 100755
index 0000000..7ef4224
--- /dev/null
+++ b/build.sh
@@ -0,0 +1,74 @@
+#!/bin/sh
+# Build ghosttyconf for the usual platforms into ./bin, auto-incrementing the
+# patch version by 0.0.1 on every build.
+#
+# version.txt holds the currently built version. Each run increments the patch
+# component, then builds every platform with that one version injected via
+# -ldflags, and writes it back. So version.txt always reflects the version of
+# the binaries just built, and all of them carry the same one. The literal in
+# version.go is only ever what a bare `go build` picks up.
+#
+# ./bin ends up with ghosttyconf--, one file per platform, which
+# `mgsh release ` attaches to the release as they are.
+#
+# Override the platform list to build just one:
+# PLATFORMS="linux/amd64" ./build.sh
+#
+# Set the version instead of bumping it:
+# VERSION=1.1.0 ./build.sh
+# The automatic bump only ever touches the last number, so a minor or major
+# step is a decision, and this is how it is made.
+#
+# Windows is not in the list: Ghostty does not run there.
+#
+# -s -w drops the symbol table and DWARF info, -trimpath keeps build paths out
+# of the binary; together they roughly halve it. Neither affects a panic trace.
+set -e
+cd "$(dirname "$0")"
+
+PLATFORMS=${PLATFORMS:-"darwin/arm64 darwin/amd64 linux/amd64 linux/arm64"}
+
+if [ -n "$VERSION" ]; then
+ # Checked rather than trusted: this number goes into the binary, into
+ # version.txt and onto the release tag.
+ if ! printf '%s' "$VERSION" | grep -Eq '^[0-9]+\.[0-9]+\.[0-9]+$'; then
+ echo "VERSION=$VERSION is not MAJOR.MINOR.PATCH" >&2
+ exit 1
+ fi
+ NV="$VERSION"
+else
+ V=$(cat version.txt 2>/dev/null || echo 1.0.0)
+
+ # split MAJOR.MINOR.PATCH and increment PATCH (no carry: 1.0.9 -> 1.0.10)
+ MAJOR=${V%%.*}
+ REST=${V#*.}
+ MINOR=${REST%%.*}
+ PATCH=${REST#*.}
+ PATCH=$((PATCH + 1))
+ NV="$MAJOR.$MINOR.$PATCH"
+fi
+
+mkdir -p bin
+HOST="$(go env GOOS)/$(go env GOARCH)"
+
+for p in $PLATFORMS; do
+ os=${p%/*}
+ arch=${p#*/}
+ out="bin/ghosttyconf-$os-$arch"
+
+ # CGO_ENABLED=0 throughout: it makes the cross builds work without a
+ # toolchain per target and the binaries static. ghosttyconf only runs
+ # ghostty and osascript and reads files, so nothing is lost by dropping cgo.
+ CGO_ENABLED=0 GOOS="$os" GOARCH="$arch" \
+ go build -trimpath -ldflags "-s -w -X main.Version=$NV" -o "$out" .
+
+ if [ "$p" = "$HOST" ]; then
+ ln -sf "ghosttyconf-$os-$arch" bin/ghosttyconf # the one for this machine
+ echo " $out -> bin/ghosttyconf"
+ else
+ echo " $out"
+ fi
+done
+
+echo "$NV" > version.txt
+echo "built ghosttyconf v$NV"
diff --git a/docs/development.md b/docs/development.md
index 1403e4d..1d00ce9 100644
--- a/docs/development.md
+++ b/docs/development.md
@@ -13,6 +13,7 @@ make install # go install
make test # go test ./...
make schema # regenerate the option schema for the installed Ghostty
make screenshots # regenerate docs/images (needs tmux and Ghostty)
+make dist # = ./build.sh: release binaries for all platforms into ./bin
```
The code builds on macOS, Linux and the BSDs. Automatic reload is implemented
@@ -23,6 +24,8 @@ for macOS and Linux. Other platforms only save.
| Path | Content |
| --- | --- |
| `main.go` | flags, startup, wiring |
+| `version.go`, `version.txt` | the version: `version.txt` is the released one, `build.sh` injects it |
+| `build.sh` | builds the release binaries into `./bin` |
| `internal/schema` | the option schema: kinds, categories, platform detection, value validation; `schema.json` is embedded |
| `internal/config` | the comment- and layout-preserving config file model, atomic saving |
| `internal/ghostty` | finding and running the `ghostty` binary (docs, themes, fonts, actions, validation), config paths, reload |
@@ -33,6 +36,34 @@ for macOS and Linux. Other platforms only save.
| `tools/termsvg` | renders captured terminal screens as SVG (for the screenshots) |
| `tools/screenshots.sh` | drives ghosttyconf in tmux and writes `docs/images/*.svg` |
+## Versions and releases
+
+The version follows `MAJOR.MINOR.PATCH`. `version.txt` holds the version of
+the last release build. `build.sh` builds `bin/ghosttyconf--` for
+macOS and Linux on arm64 and amd64. The binaries are static (`CGO_ENABLED=0`)
+and stripped, and they carry the version via `-ldflags "-X main.Version=โฆ"`.
+`make build` and `make install` use `version.txt` too. Only a plain
+`go build` reports the literal in `version.go`.
+
+```sh
+./build.sh # bump the patch number: 1.0.0 -> 1.0.1
+VERSION=1.1.0 ./build.sh # or set the version explicitly
+```
+
+A release is made with [mgsh](https://git.micw.org/mike/mgsh):
+
+```sh
+VERSION=1.1.0 ./build.sh
+mgsh push "version 1.1.0" # commit and push to the git server
+mgsh pushremote @micw # update the public mirror
+mgsh release @micw 1.1.0 "notes" # tag, publish, attach ./bin
+```
+
+`mgsh release` creates the annotated tag, pushes it and publishes the release
+on git.micw.org. Every regular file in `./bin` is attached to it. If the tag
+already exists with a longer annotation, that annotation becomes the release
+notes. `./bin` is not part of the repository.
+
## The schema
Ghostty's own documentation (`ghostty +show-config --default --docs`) contains
diff --git a/internal/ui/app.go b/internal/ui/app.go
index d75fa13..4f4d459 100644
--- a/internal/ui/app.go
+++ b/internal/ui/app.go
@@ -98,6 +98,7 @@ type App struct {
statusStyle lipgloss.Style
quitAfterSave bool
autoReload bool
+ version string
// Screen regions from the last render, for mouse handling.
catRect, optRect, docRect rect
@@ -155,6 +156,9 @@ func New(sch *schema.Schema, gh *ghostty.Ghostty, file *config.File) *App {
// after every save (on by default).
func (a *App) SetAutoReload(on bool) { a.autoReload = on }
+// SetVersion sets the program version shown in the help.
+func (a *App) SetVersion(v string) { a.version = v }
+
func (a *App) Init() tea.Cmd {
if a.gh == nil {
return nil
@@ -403,7 +407,7 @@ func (a *App) updateBrowse(km tea.KeyMsg) tea.Cmd {
case "q":
return a.quit()
case "?", "f1":
- a.dlg = helpDialog()
+ a.dlg = helpDialog(a.version)
return nil
case "/", "ctrl+f":
// Every search starts fresh, like "/" in less or vim.
diff --git a/internal/ui/dialogs.go b/internal/ui/dialogs.go
index 8a7e7d3..b4e51b3 100644
--- a/internal/ui/dialogs.go
+++ b/internal/ui/dialogs.go
@@ -99,10 +99,14 @@ func (d *dialog) view(width, height int) string {
return framed(d.title, content, w, len(lines)+2, color)
}
-func helpDialog() *dialog {
+func helpDialog(version string) *dialog {
k := func(key, desc string) string { return stKey.Render(fit(key, 16)) + desc }
+ title := "Help"
+ if version != "" {
+ title = "Help ยท ghosttyconf " + version
+ }
return &dialog{
- title: "Help",
+ title: title,
lines: []string{
stBold.Render("Browsing"),
k("โโ / j k", "move"),
diff --git a/main.go b/main.go
index de23bb8..4f585b9 100644
--- a/main.go
+++ b/main.go
@@ -21,12 +21,17 @@ func main() {
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.Fprintln(flag.CommandLine.Output(), "A terminal editor for the Ghostty configuration. Flags:")
+ 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)
@@ -79,6 +84,7 @@ func run(path, ghosttyBin string, offline, autoReload bool) error {
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()
diff --git a/version.go b/version.go
new file mode 100644
index 0000000..cd4f599
--- /dev/null
+++ b/version.go
@@ -0,0 +1,6 @@
+package main
+
+// Version is a var, not a const, so build.sh can put the built number in via
+// -ldflags "-X main.Version=โฆ". The value here only ever shows up in a bare
+// `go build`; the version actually built is the one in version.txt.
+var Version = "1.0.0"
diff --git a/version.txt b/version.txt
new file mode 100644
index 0000000..3eefcb9
--- /dev/null
+++ b/version.txt
@@ -0,0 +1 @@
+1.0.0