diff --git a/pkg/cmdrunner/cmdrunner.go b/pkg/cmdrunner/cmdrunner.go index d2a8b038..01b98639 100644 --- a/pkg/cmdrunner/cmdrunner.go +++ b/pkg/cmdrunner/cmdrunner.go @@ -68,7 +68,7 @@ var ValidCommands = []string{ "/comment", "/cd", "/compgen", - "/setenv", + "/setenv", "/unset", } func HandleCommand(ctx context.Context, pk *scpacket.FeCommandPacketType) (sstore.UpdatePacket, error) { @@ -100,6 +100,9 @@ func HandleCommand(ctx context.Context, pk *scpacket.FeCommandPacketType) (sstor case "setenv": return SetEnvCommand(ctx, pk) + case "unset": + return UnSetCommand(ctx, pk) + default: return nil, fmt.Errorf("invalid command '/%s', no handler", pk.MetaCmd) } @@ -350,6 +353,9 @@ func evalCommandInternal(ctx context.Context, pk *scpacket.FeCommandPacketType) } else if commandStr == "setenv" || strings.HasPrefix(commandStr, "setenv ") { metaCmd = "setenv" commandStr = strings.TrimSpace(commandStr[6:]) + } else if commandStr == "unset" || strings.HasPrefix(commandStr, "unset ") { + metaCmd = "unset" + commandStr = strings.TrimSpace(commandStr[5:]) } else if commandStr[0] == '/' { spaceIdx := strings.Index(commandStr, " ") if spaceIdx == -1 { @@ -437,6 +443,10 @@ func ScreenCommand(ctx context.Context, pk *scpacket.FeCommandPacketType) (sstor return update, nil } +func UnSetCommand(ctx context.Context, pk *scpacket.FeCommandPacketType) (sstore.UpdatePacket, error) { + return nil, nil +} + func SetEnvCommand(ctx context.Context, pk *scpacket.FeCommandPacketType) (sstore.UpdatePacket, error) { return nil, nil } diff --git a/pkg/remote/remote.go b/pkg/remote/remote.go index 89593cad..0ffec94a 100644 --- a/pkg/remote/remote.go +++ b/pkg/remote/remote.go @@ -115,6 +115,42 @@ func GetRemoteById(remoteId string) *MShellProc { return GlobalStore.Map[remoteId] } +func unquoteDQBashString(str string) (string, bool) { + if len(str) < 2 { + return str, false + } + if str[0] != '"' || str[len(str)-1] != '"' { + return str, false + } + rtn := make([]byte, 0, len(str)-2) + for idx := 1; idx < len(str)-1; idx++ { + ch := str[idx] + if ch == '"' { + return str, false + } + if ch == '\\' { + if idx == len(str)-2 { + return str, false + } + nextCh := str[idx+1] + if nextCh == '\n' { + idx++ + continue + } + if nextCh == '$' || nextCh == '"' || nextCh == '\\' || nextCh == '`' { + idx++ + rtn = append(rtn, nextCh) + continue + } + rtn = append(rtn, '\\') + continue + } else { + rtn = append(rtn, ch) + } + } + return string(rtn), true +} + func GetAllRemoteState() []RemoteState { GlobalStore.Lock.Lock() defer GlobalStore.Lock.Unlock() @@ -146,7 +182,10 @@ func GetAllRemoteState() []RemoteState { vars["status"] = proc.Status vars["type"] = proc.Remote.RemoteType if proc.ServerProc != nil && proc.ServerProc.InitPk != nil { - state.DefaultState = &sstore.RemoteState{Cwd: proc.ServerProc.InitPk.HomeDir} + state.DefaultState = &sstore.RemoteState{ + Cwd: proc.ServerProc.InitPk.Cwd, + Env: proc.ServerProc.InitPk.Env, + } vars["home"] = proc.ServerProc.InitPk.HomeDir vars["remoteuser"] = proc.ServerProc.InitPk.User vars["remotehost"] = proc.ServerProc.InitPk.HostName diff --git a/pkg/sstore/sstore.go b/pkg/sstore/sstore.go index b814ec4d..52e2c81f 100644 --- a/pkg/sstore/sstore.go +++ b/pkg/sstore/sstore.go @@ -230,6 +230,7 @@ type HistoryItemType struct { type RemoteState struct { Cwd string `json:"cwd"` + Env []byte `json:"env"` } func (s *RemoteState) Scan(val interface{}) error {