show environment

This commit is contained in:
sawka 2022-08-22 18:53:38 -07:00
parent 292c76808a
commit 429c41cfd0
2 changed files with 18 additions and 2 deletions

View File

@ -11,6 +11,7 @@ import (
"strings"
"time"
"github.com/alessio/shellescape"
"github.com/google/uuid"
"github.com/scripthaus-dev/mshell/pkg/base"
"github.com/scripthaus-dev/mshell/pkg/packet"
@ -524,6 +525,20 @@ func SetEnvCommand(ctx context.Context, pk *scpacket.FeCommandPacketType) (sstor
return nil, fmt.Errorf("remote state is not available")
}
envMap := shexec.ParseEnv0(ids.RemoteState.Env0)
if len(pk.Args) == 0 {
var infoLines []string
for varName, varVal := range envMap {
line := fmt.Sprintf("%s=%s", varName, shellescape.Quote(varVal))
infoLines = append(infoLines, line)
}
update := sstore.InfoUpdate{
Info: &sstore.InfoMsgType{
InfoTitle: fmt.Sprintf("[%s] environment", ids.RemoteName),
InfoLines: infoLines,
},
}
return update, nil
}
setVars := make(map[string]bool)
for _, argStr := range pk.Args {
eqIdx := strings.Index(argStr, "=")

View File

@ -84,8 +84,9 @@ type InfoMsgType struct {
InfoTitle string `json:"infotitle"`
InfoError string `json:"infoerror,omitempty"`
InfoMsg string `json:"infomsg,omitempty"`
InfoComps []string `json:"infocomps"`
InfoCompsMore bool `json:"infocompssmore"`
InfoComps []string `json:"infocomps,omitempty"`
InfoCompsMore bool `json:"infocompssmore,omitempty"`
InfoLines []string `json:"infolines,omitempty"`
TimeoutMs int64 `json:"timeoutms,omitempty"`
}