| 1 | package sandbox |
| 2 | |
| 3 | import "strings" |
| 4 | |
| 5 | // unixShellCapabilities reports the common POSIX-family interpreters present |
| 6 | // on macOS and Linux. Linux remains Bash-only for execution; macOS may fall |
| 7 | // back to zsh and then sh when Bash is unavailable, while Settings reports the |
| 8 | // complete inventory on both platforms. |
| 9 | func unixShellCapabilities(snap *shellSnapshot) []ShellCapability { |
| 10 | return []ShellCapability{ |
| 11 | unixShellCapability(snap, ShellCapabilityBash, []string{"bash"}, []string{"/bin/bash", "/usr/bin/bash"}), |
| 12 | unixShellCapability(snap, ShellCapabilityZsh, []string{"zsh"}, []string{"/bin/zsh", "/usr/bin/zsh"}), |
| 13 | unixShellCapability(snap, ShellCapabilitySh, []string{"sh"}, []string{"/bin/sh", "/usr/bin/sh"}), |
| 14 | } |
| 15 | } |
| 16 | |
| 17 | func unixShellCapability(snap *shellSnapshot, id string, names, standardPaths []string) ShellCapability { |
| 18 | capability := ShellCapability{ID: id, Variant: "system"} |
| 19 | if id == ShellCapabilityBash && strings.EqualFold(strings.TrimSpace(snap.prefer), "bash") { |
| 20 | path := configuredShellPathForPreference(snap.goos, snap.prefer, snap.configPath, snap.exists, snap.isWSL) |
| 21 | if path != "" && snap.exists(path) && snap.probe(path) { |
| 22 | capability.Available, capability.Path, capability.Source = true, path, ShellSourceConfig |
| 23 | return capability |
| 24 | } |
| 25 | } |
| 26 | for _, name := range names { |
| 27 | if path, err := snap.lookPath(name); err == nil { |
| 28 | capability.Available = true |
| 29 | capability.Path = path |
| 30 | capability.Source = ShellSourcePath |
| 31 | return capability |
| 32 | } |
| 33 | } |
| 34 | for _, path := range standardPaths { |
| 35 | if snap.exists(path) { |
| 36 | capability.Available = true |
| 37 | capability.Path = path |
| 38 | capability.Source = ShellSourceStandard |
| 39 | return capability |
| 40 | } |
| 41 | } |
| 42 | capability.Reason = "not-found" |
| 43 | return capability |
| 44 | } |
| 45 |