MCPcopy Index your code
hub / github.com/wavetermdev/waveterm / StartWslShellProc

Function StartWslShellProc

pkg/shellexec/shellexec.go:176–292  ·  view source on GitHub ↗
(ctx context.Context, termSize waveobj.TermSize, cmdStr string, cmdOpts CommandOptsType, conn *wslconn.WslConn)

Source from the content-addressed store, hash-verified

174}
175
176func StartWslShellProc(ctx context.Context, termSize waveobj.TermSize, cmdStr string, cmdOpts CommandOptsType, conn *wslconn.WslConn) (*ShellProc, error) {
177 if cmdOpts.SwapToken == nil {
178 return nil, fmt.Errorf("SwapToken is required in CommandOptsType")
179 }
180 client := conn.GetClient()
181 conn.Infof(ctx, "WSL-NEWSESSION (StartWslShellProc)")
182 connRoute := wshutil.MakeConnectionRouteId(conn.GetName())
183 rpcClient := wshclient.GetBareRpcClient()
184 remoteInfo, err := wshclient.RemoteGetInfoCommand(rpcClient, &wshrpc.RpcOpts{Route: connRoute, Timeout: 2000})
185 if err != nil {
186 return nil, fmt.Errorf("unable to obtain client info: %w", err)
187 }
188 log.Printf("client info collected: %+#v", remoteInfo)
189 var shellPath string
190 if cmdOpts.ShellPath != "" {
191 conn.Infof(ctx, "using shell path from command opts: %s\n", cmdOpts.ShellPath)
192 shellPath = cmdOpts.ShellPath
193 }
194 configShellPath := conn.GetConfigShellPath()
195 if shellPath == "" && configShellPath != "" {
196 conn.Infof(ctx, "using shell path from config (conn:shellpath): %s\n", configShellPath)
197 shellPath = configShellPath
198 }
199 if shellPath == "" && remoteInfo.Shell != "" {
200 conn.Infof(ctx, "using shell path detected on remote machine: %s\n", remoteInfo.Shell)
201 shellPath = remoteInfo.Shell
202 }
203 if shellPath == "" {
204 conn.Infof(ctx, "no shell path detected, using default (/bin/bash)\n")
205 shellPath = "/bin/bash"
206 }
207 var shellOpts []string
208 var cmdCombined string
209 log.Printf("detected shell %q for conn %q\n", shellPath, conn.GetName())
210
211 err = wshclient.RemoteInstallRcFilesCommand(rpcClient, &wshrpc.RpcOpts{Route: connRoute, Timeout: 2000})
212 if err != nil {
213 log.Printf("error installing rc files: %v", err)
214 return nil, err
215 }
216 shellOpts = append(shellOpts, cmdOpts.ShellOpts...)
217 shellType := shellutil.GetShellTypeFromShellPath(shellPath)
218 conn.Infof(ctx, "detected shell type: %s\n", shellType)
219 conn.Debugf(ctx, "cmdStr: %q\n", cmdStr)
220
221 if cmdStr == "" {
222 /* transform command in order to inject environment vars */
223 if shellType == shellutil.ShellType_bash {
224 // add --rcfile
225 // cant set -l or -i with --rcfile
226 bashPath := fmt.Sprintf("~/.waveterm/%s/.bashrc", shellutil.BashIntegrationDir)
227 shellOpts = append(shellOpts, "--rcfile", bashPath)
228 } else if shellType == shellutil.ShellType_fish {
229 if cmdOpts.Login {
230 shellOpts = append(shellOpts, "-l")
231 }
232 // source the wave.fish file
233 waveFishPath := fmt.Sprintf("~/.waveterm/%s/wave.fish", shellutil.FishIntegrationDir)

Callers 1

Calls 14

MakeConnectionRouteIdFunction · 0.92
GetBareRpcClientFunction · 0.92
RemoteGetInfoCommandFunction · 0.92
AddTokenSwapEntryFunction · 0.92
MakeCmdWrapFunction · 0.85
PackForClientMethod · 0.80
GetClientMethod · 0.45
InfofMethod · 0.45
GetNameMethod · 0.45
GetConfigShellPathMethod · 0.45

Tested by

no test coverage detected