(ctx context.Context, logCtx context.Context, termSize waveobj.TermSize, cmdStr string, cmdOpts CommandOptsType, conn *conncontroller.SSHConn)
| 335 | } |
| 336 | |
| 337 | func StartRemoteShellProc(ctx context.Context, logCtx context.Context, termSize waveobj.TermSize, cmdStr string, cmdOpts CommandOptsType, conn *conncontroller.SSHConn) (*ShellProc, error) { |
| 338 | if cmdOpts.SwapToken == nil { |
| 339 | return nil, fmt.Errorf("SwapToken is required in CommandOptsType") |
| 340 | } |
| 341 | client := conn.GetClient() |
| 342 | connRoute := wshutil.MakeConnectionRouteId(conn.GetName()) |
| 343 | rpcClient := wshclient.GetBareRpcClient() |
| 344 | remoteInfo, err := wshclient.RemoteGetInfoCommand(rpcClient, &wshrpc.RpcOpts{Route: connRoute, Timeout: 2000}) |
| 345 | if err != nil { |
| 346 | return nil, fmt.Errorf("unable to obtain client info: %w", err) |
| 347 | } |
| 348 | if remoteInfo.HomeDir == "" { |
| 349 | return nil, fmt.Errorf("unable to obtain home directory from remote machine") |
| 350 | } |
| 351 | log.Printf("client info collected: %+#v", remoteInfo) |
| 352 | var shellPath string |
| 353 | if cmdOpts.ShellPath != "" { |
| 354 | conn.Infof(logCtx, "using shell path from command opts: %s\n", cmdOpts.ShellPath) |
| 355 | shellPath = cmdOpts.ShellPath |
| 356 | } |
| 357 | configShellPath := conn.GetConfigShellPath() |
| 358 | if shellPath == "" && configShellPath != "" { |
| 359 | conn.Infof(logCtx, "using shell path from config (conn:shellpath): %s\n", configShellPath) |
| 360 | shellPath = configShellPath |
| 361 | } |
| 362 | if shellPath == "" && remoteInfo.Shell != "" { |
| 363 | conn.Infof(logCtx, "using shell path detected on remote machine: %s\n", remoteInfo.Shell) |
| 364 | shellPath = remoteInfo.Shell |
| 365 | } |
| 366 | if shellPath == "" { |
| 367 | conn.Infof(logCtx, "no shell path detected, using default (/bin/bash)\n") |
| 368 | shellPath = "/bin/bash" |
| 369 | } |
| 370 | var shellOpts []string |
| 371 | var cmdCombined string |
| 372 | log.Printf("detected shell %q for conn %q\n", shellPath, conn.GetName()) |
| 373 | shellOpts = append(shellOpts, cmdOpts.ShellOpts...) |
| 374 | shellType := shellutil.GetShellTypeFromShellPath(shellPath) |
| 375 | conn.Infof(logCtx, "detected shell type: %s\n", shellType) |
| 376 | conn.Infof(logCtx, "swaptoken: %s\n", cmdOpts.SwapToken.Token) |
| 377 | conn.Debugf(logCtx, "cmdStr: %q\n", cmdStr) |
| 378 | |
| 379 | if cmdStr == "" { |
| 380 | /* transform command in order to inject environment vars */ |
| 381 | if shellType == shellutil.ShellType_bash { |
| 382 | // add --rcfile |
| 383 | // cant set -l or -i with --rcfile |
| 384 | bashPath := fmt.Sprintf("%s/.waveterm/%s/.bashrc", remoteInfo.HomeDir, shellutil.BashIntegrationDir) |
| 385 | shellOpts = append(shellOpts, "--rcfile", bashPath) |
| 386 | } else if shellType == shellutil.ShellType_fish { |
| 387 | if cmdOpts.Login { |
| 388 | shellOpts = append(shellOpts, "-l") |
| 389 | } |
| 390 | // source the wave.fish file |
| 391 | waveFishPath := fmt.Sprintf("%s/.waveterm/%s/wave.fish", remoteInfo.HomeDir, shellutil.FishIntegrationDir) |
| 392 | carg := fmt.Sprintf(`"source %s"`, waveFishPath) |
| 393 | shellOpts = append(shellOpts, "-C", carg) |
| 394 | } else if shellType == shellutil.ShellType_pwsh { |
no test coverage detected