diff options
Diffstat (limited to 'runner/shell/shell.go')
| -rw-r--r-- | runner/shell/shell.go | 47 |
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 "" +} |
