| 1 | package main |
| 2 | |
| 3 | import ( |
| 4 | "os/exec" |
| 5 | "path/filepath" |
| 6 | "strings" |
| 7 | |
| 8 | "reasonix/internal/sandbox" |
| 9 | ) |
| 10 | |
| 11 | // terminalCommandFromConfig follows the shell tool's configured-path safety |
| 12 | // contract while keeping the integrated terminal's default-shell selection in |
| 13 | // its own owner. Rejected stale paths fall through to normal shell discovery. |
| 14 | func terminalCommandFromConfig(prefer, configuredPath string) (terminalCommand, bool) { |
| 15 | prefer = strings.ToLower(strings.TrimSpace(prefer)) |
| 16 | if prefer == "" || prefer == "auto" { |
| 17 | return terminalCommand{}, false |
| 18 | } |
| 19 | if prefer != "bash" && prefer != "powershell" && prefer != "pwsh" { |
| 20 | return terminalCommand{}, false |
| 21 | } |
| 22 | configuredPath = sandbox.ConfiguredShellPathForPreference(prefer, configuredPath) |
| 23 | if configuredPath != "" { |
| 24 | if path, err := exec.LookPath(configuredPath); err == nil { |
| 25 | label := strings.TrimSuffix(filepath.Base(path), filepath.Ext(path)) |
| 26 | return commandForShellPath(path, label), true |
| 27 | } |
| 28 | } |
| 29 | resolved := sandbox.ResolveShell(prefer, "", nil) |
| 30 | path, err := exec.LookPath(resolved.Path) |
| 31 | if err != nil { |
| 32 | return terminalCommand{}, false |
| 33 | } |
| 34 | label := strings.TrimSuffix(filepath.Base(path), filepath.Ext(path)) |
| 35 | return commandForShellPath(path, label), true |
| 36 | } |
| 37 |