forked from JanDeDobbeleer/oh-my-posh
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsegment_command.go
59 lines (52 loc) · 1.26 KB
/
segment_command.go
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package main
import "strings"
type command struct {
props *properties
env environmentInfo
value string
}
const (
//ExecutableShell to execute command in
ExecutableShell Property = "shell"
//Command to execute
Command Property = "command"
)
func (c *command) enabled() bool {
shell := c.props.getString(ExecutableShell, "bash")
if !c.env.hasCommand(shell) {
return false
}
command := c.props.getString(Command, "echo no command specified")
if strings.Contains(command, "||") {
commands := strings.Split(command, "||")
for _, cmd := range commands {
output := c.env.runShellCommand(shell, cmd)
if output != "" {
c.value = output
return true
}
}
}
if strings.Contains(command, "&&") {
var output string
commands := strings.Split(command, "&&")
for _, cmd := range commands {
output += c.env.runShellCommand(shell, cmd)
}
c.value = output
return c.value != ""
}
c.value = c.env.runShellCommand(shell, command)
return c.value != ""
}
func (c *command) string() string {
return c.value
}
// func (c *command) runCommand(command string) string {
// args := strings.Fields(command)
// return c.env.runCommand(args[0], args[1:]...)
// }
func (c *command) init(props *properties, env environmentInfo) {
c.props = props
c.env = env
}