(shellPath string)
| 492 | } |
| 493 | |
| 494 | func DetectShellTypeAndVersionFromPath(shellPath string) (string, string, error) { |
| 495 | shellType := GetShellTypeFromShellPath(shellPath) |
| 496 | if shellType == ShellType_unknown { |
| 497 | return shellType, "", fmt.Errorf("unknown shell type: %s", shellPath) |
| 498 | } |
| 499 | |
| 500 | shellBase := filepath.Base(shellPath) |
| 501 | if shellType == ShellType_pwsh && strings.Contains(shellBase, "powershell") && !strings.Contains(shellBase, "pwsh") { |
| 502 | return "powershell", "", nil |
| 503 | } |
| 504 | |
| 505 | version, err := getShellVersion(shellPath, shellType) |
| 506 | if err != nil { |
| 507 | return shellType, "", err |
| 508 | } |
| 509 | |
| 510 | return shellType, version, nil |
| 511 | } |
| 512 | |
| 513 | func getShellVersion(shellPath string, shellType string) (string, error) { |
| 514 | ctx, cancelFn := context.WithTimeout(context.Background(), 2*time.Second) |
no test coverage detected