mirror of
https://github.com/JanDeDobbeleer/oh-my-posh.git
synced 2025-02-02 05:41:10 -08:00
feat: add OS template property
This commit is contained in:
parent
608b486f8b
commit
52b66d1e5b
|
@ -50,3 +50,7 @@ Display OS specific info. Defaults to Icon.
|
||||||
- sabayon: `string` - the icon to use for Sabayon - defaults to Sabayon icon - defaults to `\uF317`
|
- sabayon: `string` - the icon to use for Sabayon - defaults to Sabayon icon - defaults to `\uF317`
|
||||||
- slackware: `string` - the icon to use for Slackware - defaults to Slackware icon - defaults to `\uF319`
|
- slackware: `string` - the icon to use for Slackware - defaults to Slackware icon - defaults to `\uF319`
|
||||||
- ubuntu: `string` - the icon to use for Ubuntu - defaults to Ubuntu icon - defaults to `\uF31b`
|
- ubuntu: `string` - the icon to use for Ubuntu - defaults to Ubuntu icon - defaults to `\uF31b`
|
||||||
|
|
||||||
|
## Template Properties
|
||||||
|
|
||||||
|
- `.OS`: `string` - the OS platform
|
||||||
|
|
|
@ -21,6 +21,8 @@ import (
|
||||||
const (
|
const (
|
||||||
unknown = "unknown"
|
unknown = "unknown"
|
||||||
windowsPlatform = "windows"
|
windowsPlatform = "windows"
|
||||||
|
darwinPlatform = "darwin"
|
||||||
|
linuxPlatform = "linux"
|
||||||
)
|
)
|
||||||
|
|
||||||
type commandError struct {
|
type commandError struct {
|
||||||
|
|
|
@ -7,6 +7,7 @@ import (
|
||||||
type osInfo struct {
|
type osInfo struct {
|
||||||
props *properties
|
props *properties
|
||||||
env environmentInfo
|
env environmentInfo
|
||||||
|
OS string
|
||||||
}
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -70,20 +71,25 @@ func (n *osInfo) string() string {
|
||||||
goos := n.env.getRuntimeGOOS()
|
goos := n.env.getRuntimeGOOS()
|
||||||
switch goos {
|
switch goos {
|
||||||
case windowsPlatform:
|
case windowsPlatform:
|
||||||
|
n.OS = windowsPlatform
|
||||||
return n.props.getString(Windows, "\uE62A")
|
return n.props.getString(Windows, "\uE62A")
|
||||||
case "darwin":
|
case darwinPlatform:
|
||||||
|
n.OS = darwinPlatform
|
||||||
return n.props.getString(MacOS, "\uF179")
|
return n.props.getString(MacOS, "\uF179")
|
||||||
case "linux":
|
case linuxPlatform:
|
||||||
wsl := n.env.getenv("WSL_DISTRO_NAME")
|
wsl := n.env.getenv("WSL_DISTRO_NAME")
|
||||||
p := n.env.getPlatform()
|
p := n.env.getPlatform()
|
||||||
if len(wsl) == 0 {
|
if len(wsl) == 0 {
|
||||||
|
n.OS = p
|
||||||
return n.getDistroName(p, "")
|
return n.getDistroName(p, "")
|
||||||
}
|
}
|
||||||
|
n.OS = wsl
|
||||||
return fmt.Sprintf("%s%s%s",
|
return fmt.Sprintf("%s%s%s",
|
||||||
n.props.getString(WSL, "WSL"),
|
n.props.getString(WSL, "WSL"),
|
||||||
n.props.getString(WSLSeparator, " - "),
|
n.props.getString(WSLSeparator, " - "),
|
||||||
n.getDistroName(p, wsl))
|
n.getDistroName(p, wsl))
|
||||||
default:
|
default:
|
||||||
|
n.OS = goos
|
||||||
return goos
|
return goos
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -78,5 +78,12 @@ func TestOSInfo(t *testing.T) {
|
||||||
props: props,
|
props: props,
|
||||||
}
|
}
|
||||||
assert.Equal(t, tc.ExpectedString, osInfo.string(), tc.Case)
|
assert.Equal(t, tc.ExpectedString, osInfo.string(), tc.Case)
|
||||||
|
if tc.WSLDistro != "" {
|
||||||
|
assert.Equal(t, tc.WSLDistro, osInfo.OS, tc.Case)
|
||||||
|
} else if tc.Platform != "" {
|
||||||
|
assert.Equal(t, tc.Platform, osInfo.OS, tc.Case)
|
||||||
|
} else {
|
||||||
|
assert.Equal(t, tc.GOOS, osInfo.OS, tc.Case)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue