(shellPath string, shellType string)
| 511 | } |
| 512 | |
| 513 | func getShellVersion(shellPath string, shellType string) (string, error) { |
| 514 | ctx, cancelFn := context.WithTimeout(context.Background(), 2*time.Second) |
| 515 | defer cancelFn() |
| 516 | |
| 517 | var cmd *exec.Cmd |
| 518 | var versionRegex *regexp.Regexp |
| 519 | |
| 520 | switch shellType { |
| 521 | case ShellType_bash: |
| 522 | cmd = exec.CommandContext(ctx, shellPath, "--version") |
| 523 | versionRegex = bashVersionRegexp |
| 524 | case ShellType_zsh: |
| 525 | cmd = exec.CommandContext(ctx, shellPath, "--version") |
| 526 | versionRegex = zshVersionRegexp |
| 527 | case ShellType_fish: |
| 528 | cmd = exec.CommandContext(ctx, shellPath, "--version") |
| 529 | versionRegex = fishVersionRegexp |
| 530 | case ShellType_pwsh: |
| 531 | cmd = exec.CommandContext(ctx, shellPath, "--version") |
| 532 | versionRegex = pwshVersionRegexp |
| 533 | default: |
| 534 | return "", fmt.Errorf("unsupported shell type: %s", shellType) |
| 535 | } |
| 536 | |
| 537 | output, err := cmd.CombinedOutput() |
| 538 | if err != nil { |
| 539 | return "", fmt.Errorf("failed to get version for %s: %w", shellType, err) |
| 540 | } |
| 541 | |
| 542 | outputStr := strings.TrimSpace(string(output)) |
| 543 | matches := versionRegex.FindStringSubmatch(outputStr) |
| 544 | if len(matches) < 2 { |
| 545 | return "", fmt.Errorf("failed to parse version from output: %q", outputStr) |
| 546 | } |
| 547 | |
| 548 | return matches[1], nil |
| 549 | } |
| 550 | |
| 551 | func FixupWaveZshHistory() error { |
| 552 | if runtime.GOOS != "darwin" { |
no test coverage detected