initial commit [141.14.140.180,mike]

This commit is contained in:
mike committed 2026-10-22 13:21:28 +02:00
commit 156bb18c91
50 files changed
+13466

No files matched your search

+61
View File
@@ -0,0 +1,61 @@
package ghostty
import (
"errors"
"os"
"path/filepath"
"strconv"
"strings"
"syscall"
)
// reload sends SIGUSR2 to the user's running Ghostty apps, which makes the
// GTK app reload its configuration.
func reload() error {
pids := ghosttyApps("/proc", os.Getuid())
if len(pids) == 0 {
return ErrNotRunning
}
var errs []error
for _, pid := range pids {
if err := syscall.Kill(pid, syscall.SIGUSR2); err != nil {
errs = append(errs, err)
}
}
if len(errs) == len(pids) {
return errors.Join(errs...)
}
return nil
}
// ghosttyApps finds Ghostty GUI processes owned by uid. CLI invocations
// such as "ghostty +list-themes" are skipped: they do not handle SIGUSR2 and
// would be terminated by it.
func ghosttyApps(proc string, uid int) []int {
entries, err := os.ReadDir(proc)
if err != nil {
return nil
}
var pids []int
for _, e := range entries {
pid, err := strconv.Atoi(e.Name())
if err != nil || pid == os.Getpid() {
continue
}
dir := filepath.Join(proc, e.Name())
comm, err := os.ReadFile(filepath.Join(dir, "comm"))
if err != nil || strings.TrimSpace(string(comm)) != "ghostty" {
continue
}
var st syscall.Stat_t
if err := syscall.Stat(dir, &st); err != nil || int(st.Uid) != uid {
continue
}
cmdline, err := os.ReadFile(filepath.Join(dir, "cmdline"))
if err != nil || isCLIAction(cmdline) {
continue
}
pids = append(pids, pid)
}
return pids
}