mirror of
https://github.com/JanDeDobbeleer/oh-my-posh.git
synced 2024-11-10 04:54:03 -08:00
57 lines
1.2 KiB
Go
57 lines
1.2 KiB
Go
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")
|
|
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
|
|
}
|