oh-my-posh/src/segments/terraform.go

32 lines
626 B
Go
Raw Normal View History

2022-01-26 06:54:36 -08:00
package segments
2020-10-16 07:25:38 -07:00
import (
"oh-my-posh/environment"
"oh-my-posh/properties"
)
2022-01-26 05:10:18 -08:00
type Terraform struct {
props properties.Properties
env environment.Environment
2021-11-20 02:14:26 -08:00
WorkspaceName string
2020-10-16 07:25:38 -07:00
}
func (tf *Terraform) Template() string {
2022-02-01 05:07:58 -08:00
return " {{ .WorkspaceName }} "
2020-10-16 07:25:38 -07:00
}
func (tf *Terraform) Init(props properties.Properties, env environment.Environment) {
2020-10-16 07:25:38 -07:00
tf.props = props
tf.env = env
}
func (tf *Terraform) Enabled() bool {
cmd := "terraform"
if !tf.env.HasCommand(cmd) || !tf.env.HasFolder(tf.env.Pwd()+"/.terraform") {
2020-10-16 07:25:38 -07:00
return false
}
tf.WorkspaceName, _ = tf.env.RunCommand(cmd, "workspace", "show")
2020-10-16 07:25:38 -07:00
return true
}