Files
ghosttyconf/internal/ghostty/reload.go
T

39 lines
1.1 KiB
Go

package ghostty
import (
"bytes"
"errors"
)
// ErrNotRunning is returned by Reload when no Ghostty instance was found.
var ErrNotRunning = errors.New("Ghostty is not running")
// ErrReloadUnsupported is returned by Reload on platforms where Ghostty
// cannot be asked to reload from outside.
var ErrReloadUnsupported = errors.New("automatic reload is not supported on this platform")
// Reload asks every running Ghostty instance to reload its configuration,
// as if the reload_config action (⌘⇧, / ctrl+shift+,) had been triggered.
//
// On macOS this uses Ghostty's AppleScript "perform action" command, on
// Linux the SIGUSR2 handler of the GTK app.
func Reload() error {
return reload()
}
// isCLIAction reports whether a NUL-separated command line runs a Ghostty
// CLI action ("ghostty +validate-config", …) rather than the app. Like
// Ghostty, it only looks at arguments before "-e".
func isCLIAction(cmdline []byte) bool {
args := bytes.Split(bytes.TrimRight(cmdline, "\x00"), []byte{0})
for _, a := range args[1:] {
if string(a) == "-e" {
break
}
if bytes.HasPrefix(a, []byte("+")) {
return true
}
}
return false
}