mirror of
https://github.com/JanDeDobbeleer/oh-my-posh.git
synced 2024-12-27 11:59:40 -08:00
9875de38d9
resolves #157
47 lines
890 B
Go
47 lines
890 B
Go
package main
|
|
|
|
import "regexp"
|
|
|
|
type language struct {
|
|
props *properties
|
|
env environmentInfo
|
|
extensions []string
|
|
commands []string
|
|
versionParam string
|
|
versionRegex string
|
|
version string
|
|
}
|
|
|
|
func (l *language) string() string {
|
|
if l.props.getBool(DisplayVersion, true) {
|
|
return l.version
|
|
}
|
|
return ""
|
|
}
|
|
|
|
func (l *language) enabled() bool {
|
|
for i, extension := range l.extensions {
|
|
if l.env.hasFiles(extension) {
|
|
break
|
|
}
|
|
if i == len(l.extensions)-1 {
|
|
return false
|
|
}
|
|
}
|
|
var executable string
|
|
for i, command := range l.commands {
|
|
if l.env.hasCommand(command) {
|
|
executable = command
|
|
break
|
|
}
|
|
if i == len(l.commands)-1 {
|
|
return false
|
|
}
|
|
}
|
|
versionInfo, _ := l.env.runCommand(executable, l.versionParam)
|
|
r := regexp.MustCompile(l.versionRegex)
|
|
values := groupDict(r, versionInfo)
|
|
l.version = values["version"]
|
|
return true
|
|
}
|