summaryrefslogtreecommitdiff
path: root/runner
diff options
context:
space:
mode:
authorewy <ewy0@protonmail.com>2026-07-11 16:46:25 +0200
committerewy <ewy0@protonmail.com>2026-07-11 16:46:25 +0200
commit8c18b05df43d2876a6e78611c8b9b9b72f6516f0 (patch)
tree32050674e0ac8dd2b17872d5043904f3a11c23d8 /runner
parentfc02503aa3b916cb596767a4ba4ca5a1971ca4c7 (diff)
make ext shell map very explicit
Diffstat (limited to 'runner')
-rw-r--r--runner/shell/shell.go47
1 files changed, 25 insertions, 22 deletions
diff --git a/runner/shell/shell.go b/runner/shell/shell.go
index 235e9cd..39fdf79 100644
--- a/runner/shell/shell.go
+++ b/runner/shell/shell.go
@@ -22,8 +22,10 @@ var NoContentError = errors.New("not enough content in target")
var NoShellError = errors.New("could not find any shell interpreters")
var ExtShellMap = map[string]string{
- ".sh": "bash",
- ".ps1": "powershell",
+ ".bash": "bash",
+ ".fish": "fish",
+ ".ps1": "powershell",
+ ".bat": "cmd",
}
var Shells = []string{"bash", "bash.exe", "zsh", "fish", "dash", "sh", "powershell", "powershell.exe", "cmd.exe"}
@@ -127,32 +129,22 @@ func (s *shell) ShellFor(fs fs.FS, file string) (string, error) {
txt := scanner.Text()
if strings.HasPrefix(txt, "#!") {
// shebang found
- for _, potentialShell := range Shells {
- if strings.Contains(txt, potentialShell) {
- shebang = shell
- if loc, err := s.Find(potentialShell); err == nil {
- shell = loc
- } else {
- _, _ = spool.Warn("script has %s but could not find %s\n", shebang, potentialShell)
- }
- }
+ byShebang := s.ShellByShebang(txt)
+ if byShebang != "" {
+ return byShebang, nil
+ } else {
+ _, _ = spool.Warn("script has %s but could not find %s\n", shebang)
}
}
- if shebang == "" {
- // if no shebang, just send the first one we find
- for _, s := range Shells {
- if p, err := exec.LookPath(s); err != nil {
- shell = p
- }
+ // if no shebang, just send the first one we find
+ for _, s := range Shells {
+ if p, err := exec.LookPath(s); err != nil {
+ shell = p
}
}
- if shell == "" {
- return "", NoShellError
- }
-
- return shell, nil
+ return "", NoShellError
}
@@ -167,3 +159,14 @@ func (s *shell) ShellByFilename(file string) string {
return ""
}
+
+func (s *shell) ShellByShebang(line string) string {
+ for _, s := range Shells {
+ if strings.Contains(line, s) {
+ if p, err := exec.LookPath(s); err == nil {
+ return p
+ }
+ }
+ }
+ return ""
+}