diff --git a/pkg/cmdrunner/cmdrunner.go b/pkg/cmdrunner/cmdrunner.go index de84d097..5623526f 100644 --- a/pkg/cmdrunner/cmdrunner.go +++ b/pkg/cmdrunner/cmdrunner.go @@ -11,6 +11,7 @@ import ( "sort" "strconv" "strings" + "syscall" "time" "github.com/alessio/shellescape" @@ -41,7 +42,7 @@ var RemoteSetArgs = []string{"alias", "connectmode", "key", "password", "autoins var WindowCmds = []string{"run", "comment", "cd", "cr", "clear", "sw", "alias", "unalias", "function", "reset"} var NoHistCmds = []string{"compgen", "line", "history"} -var GlobalCmds = []string{"session", "screen", "remote"} +var GlobalCmds = []string{"session", "screen", "remote", "killserver"} var hostNameRe = regexp.MustCompile("^[a-z][a-z0-9.-]*$") var userHostRe = regexp.MustCompile("^(sudo@)?([a-z][a-z0-9-]*)@([a-z][a-z0-9.-]*)(?::([0-9]+))?$") @@ -112,6 +113,8 @@ func init() { registerCmdFn("line:show", LineShowCommand) registerCmdFn("history", HistoryCommand) + + registerCmdFn("killserver", KillServerCommand) } func getValidCommands() []string { @@ -1661,6 +1664,15 @@ func LineShowCommand(ctx context.Context, pk *scpacket.FeCommandPacketType) (sst return update, nil } +func KillServerCommand(ctx context.Context, pk *scpacket.FeCommandPacketType) (sstore.UpdatePacket, error) { + go func() { + fmt.Printf("received /killserver, shutting down\n") + time.Sleep(1 * time.Second) + syscall.Kill(syscall.Getpid(), syscall.SIGINT) + }() + return nil, nil +} + func formatTermOpts(termOpts sstore.TermOpts) string { if termOpts.Cols == 0 { return "???" diff --git a/pkg/sstore/updatebus.go b/pkg/sstore/updatebus.go index 5d3baf6b..b5ad0961 100644 --- a/pkg/sstore/updatebus.go +++ b/pkg/sstore/updatebus.go @@ -37,6 +37,7 @@ type ModelUpdate struct { Cmd *CmdType `json:"cmd,omitempty"` CmdLine *CmdLineType `json:"cmdline,omitempty"` Info *InfoMsgType `json:"info,omitempty"` + ClearInfo bool `json:"clearinfo,omitempty"` Remotes []interface{} `json:"remotes,omitempty"` // []*remote.RemoteState History *HistoryInfoType `json:"history,omitempty"` Interactive bool `json:"interactive"` diff --git a/scripthaus.md b/scripthaus.md index 6ae41862..a7f1964d 100644 --- a/scripthaus.md +++ b/scripthaus.md @@ -12,5 +12,5 @@ sqlite3 /Users/mike/scripthaus/sh2.db ```bash # @scripthaus command build -go build -o server cmd/main-server.go +go build -o ~/scripthaus/local-server cmd/main-server.go ```