diff --git a/pkg/cmdrunner/cmdrunner.go b/pkg/cmdrunner/cmdrunner.go index a56bca090..a20bec268 100644 --- a/pkg/cmdrunner/cmdrunner.go +++ b/pkg/cmdrunner/cmdrunner.go @@ -124,6 +124,7 @@ func init() { registerCmdFn("clear", ClearCommand) registerCmdFn("reset", RemoteResetCommand) registerCmdFn("signal", SignalCommand) + registerCmdFn("sync", SyncCommand) registerCmdFn("session", SessionCommand) registerCmdFn("session:open", SessionOpenCommand) @@ -393,6 +394,39 @@ func getEvalDepth(ctx context.Context) int { return depthVal.(int) } +func SyncCommand(ctx context.Context, pk *scpacket.FeCommandPacketType) (sstore.UpdatePacket, error) { + ids, err := resolveUiIds(ctx, pk, R_Session|R_Screen|R_RemoteConnected) + if err != nil { + return nil, fmt.Errorf("/run error: %w", err) + } + runPacket := packet.MakeRunPacket() + runPacket.ReqId = uuid.New().String() + runPacket.CK = base.MakeCommandKey(ids.ScreenId, scbase.GenPromptUUID()) + runPacket.UsePty = true + ptermVal := defaultStr(pk.Kwargs["pterm"], DefaultPTERM) + runPacket.TermOpts, err = GetUITermOpts(pk.UIContext.WinSize, ptermVal) + if err != nil { + return nil, fmt.Errorf("/sync error, invalid 'pterm' value %q: %v", ptermVal, err) + } + runPacket.Command = ":" + runPacket.ReturnState = true + cmd, callback, err := remote.RunCommand(ctx, ids.SessionId, ids.ScreenId, ids.Remote.RemotePtr, runPacket) + if callback != nil { + defer callback() + } + if err != nil { + return nil, err + } + cmd.RawCmdStr = pk.GetRawStr() + update, err := addLineForCmd(ctx, "/sync", true, ids, cmd, "terminal") + if err != nil { + return nil, err + } + update.Interactive = pk.Interactive + sstore.MainBus.SendScreenUpdate(ids.ScreenId, update) + return nil, nil +} + func RunCommand(ctx context.Context, pk *scpacket.FeCommandPacketType) (sstore.UpdatePacket, error) { ids, err := resolveUiIds(ctx, pk, R_Session|R_Screen|R_RemoteConnected) if err != nil { diff --git a/pkg/remote/remote.go b/pkg/remote/remote.go index 699f4e85b..cfd786dc8 100644 --- a/pkg/remote/remote.go +++ b/pkg/remote/remote.go @@ -584,12 +584,17 @@ func (msh *MShellProc) GetRemoteRuntimeState() RemoteRuntimeState { vars["color"] = msh.Remote.RemoteOpts.Color } if msh.ServerProc != nil && msh.ServerProc.InitPk != nil { - state.MShellVersion = msh.ServerProc.InitPk.Version - vars["home"] = msh.ServerProc.InitPk.HomeDir - vars["remoteuser"] = msh.ServerProc.InitPk.User + initPk := msh.ServerProc.InitPk + if initPk.BuildTime == "" || initPk.BuildTime == "0" { + state.MShellVersion = initPk.Version + } else { + state.MShellVersion = fmt.Sprintf("%s+%s", initPk.Version, initPk.BuildTime) + } + vars["home"] = initPk.HomeDir + vars["remoteuser"] = initPk.User vars["bestuser"] = vars["remoteuser"] - vars["remotehost"] = msh.ServerProc.InitPk.HostName - vars["remoteshorthost"] = makeShortHost(msh.ServerProc.InitPk.HostName) + vars["remotehost"] = initPk.HostName + vars["remoteshorthost"] = makeShortHost(initPk.HostName) vars["besthost"] = vars["remotehost"] vars["bestshorthost"] = vars["remoteshorthost"] }