-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshell.go
More file actions
40 lines (31 loc) · 719 Bytes
/
shell.go
File metadata and controls
40 lines (31 loc) · 719 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package main
import (
"fmt"
"path/filepath"
"strings"
)
type Shell struct {
Path string
}
func (s *Shell) Build(cmd string, args []string) []string {
if cmd == "" {
return []string{s.Path}
}
var command []string
exe := strings.ToLower(filepath.Base(s.Path))
switch exe {
case "cmd.exe":
command = []string{s.Path, "/c"}
case "powershell.exe", "pwsh.exe":
command = []string{s.Path, "-NoProfile", "-Command"}
case "bash.exe", "zsh.exe", "fish.exe", "git-bash.exe", "nu.exe":
command = []string{s.Path, "-c"}
}
if len(command) == 0 {
return append([]string{cmd}, args...)
}
if len(args) > 0 {
cmd = fmt.Sprintf("%s %s", cmd, strings.Join(args, " "))
}
return append(command, cmd)
}