oh-my-posh/segment_os.go

137 lines
3.8 KiB
Go
Raw Normal View History

2020-10-07 12:01:03 -07:00
package main
2020-10-21 19:49:14 -07:00
import (
"fmt"
)
2020-10-07 12:01:03 -07:00
type osInfo struct {
2020-10-09 03:51:22 -07:00
props *properties
env environmentInfo
2020-10-07 12:01:03 -07:00
}
const (
// MacOS the string/icon to use for MacOS
2020-10-09 03:51:22 -07:00
MacOS Property = "macos"
// Linux the string/icon to use for linux
2020-10-07 12:01:03 -07:00
Linux Property = "linux"
// Windows the string/icon to use for windows
2020-10-07 12:01:03 -07:00
Windows Property = "windows"
// WSL the string/icon to use for WSL
2020-10-21 19:49:14 -07:00
WSL Property = "wsl"
// WSLSeparator shows between WSL and Linux properties when WSL is detected
2020-10-21 19:49:14 -07:00
WSLSeparator Property = "wsl_separator"
// Alpine the string/icon to use for Alpine
2020-10-21 19:49:14 -07:00
Alpine Property = "alpine"
// Aosc the string/icon to use for Aosc
2020-10-21 19:49:14 -07:00
Aosc Property = "aosc"
// Arch the string/icon to use for Arch
2020-10-21 19:49:14 -07:00
Arch Property = "arch"
// Centos the string/icon to use for Centos
2020-10-21 19:49:14 -07:00
Centos Property = "centos"
// Coreos the string/icon to use for Coreos
2020-10-21 19:49:14 -07:00
Coreos Property = "coreos"
// Debian the string/icon to use for Debian
2020-10-21 19:49:14 -07:00
Debian Property = "debian"
// Devuan the string/icon to use for Devuan
2020-10-21 19:49:14 -07:00
Devuan Property = "devuan"
// Raspbian the string/icon to use for Raspbian
2020-10-21 19:49:14 -07:00
Raspbian Property = "raspbian"
// Elementary the string/icon to use for Elementary
2020-10-21 19:49:14 -07:00
Elementary Property = "elementary"
// Fedora the string/icon to use for Fedora
2020-10-21 19:49:14 -07:00
Fedora Property = "fedora"
// Gentoo the string/icon to use for Gentoo
2020-10-21 19:49:14 -07:00
Gentoo Property = "gentoo"
// Mageia the string/icon to use for Mageia
2020-10-21 19:49:14 -07:00
Mageia Property = "mageia"
// Manjaro the string/icon to use for Manjaro
2020-10-21 19:49:14 -07:00
Manjaro Property = "manjaro"
// Mint the string/icon to use for Mint
2020-10-21 19:49:14 -07:00
Mint Property = "mint"
// Nixos the string/icon to use for Nixos
2020-10-21 19:49:14 -07:00
Nixos Property = "nixos"
// Opensuse the string/icon to use for Opensuse
2020-10-21 19:49:14 -07:00
Opensuse Property = "opensuse"
// Sabayon the string/icon to use for Sabayon
2020-10-21 19:49:14 -07:00
Sabayon Property = "sabayon"
// Slackware the string/icon to use for Slackware
2020-10-21 19:49:14 -07:00
Slackware Property = "slackware"
// Ubuntu the string/icon to use for Ubuntu
2020-10-21 19:49:14 -07:00
Ubuntu Property = "ubuntu"
2020-10-07 12:01:03 -07:00
)
func (n *osInfo) enabled() bool {
return true
}
func (n *osInfo) string() string {
goos := n.env.getRuntimeGOOS()
switch goos {
case windowsPlatform:
2020-10-07 12:01:03 -07:00
return n.props.getString(Windows, "\uE62A")
case "darwin":
2020-10-09 03:51:22 -07:00
return n.props.getString(MacOS, "\uF179")
2020-10-07 12:01:03 -07:00
case "linux":
2020-10-21 19:49:14 -07:00
wsl := n.env.getenv("WSL_DISTRO_NAME")
p := n.env.getPlatform()
if wsl != "" {
return fmt.Sprintf("%s%s%s",
n.props.getString(WSL, "WSL"),
n.props.getString(WSLSeparator, " - "),
getLinuxIcon(n, p))
}
return getLinuxIcon(n, p)
2020-10-07 12:01:03 -07:00
default:
return ""
}
}
2020-10-21 19:49:14 -07:00
func getLinuxIcon(n *osInfo, p string) string {
switch p {
case "alpine":
return n.props.getString(Alpine, "\uF300")
case "aosc":
return n.props.getString(Aosc, "\uF301")
case "arch":
return n.props.getString(Arch, "\uF303")
case "centos":
return n.props.getString(Centos, "\uF304")
case "coreos":
return n.props.getString(Coreos, "\uF305")
case "debian":
return n.props.getString(Debian, "\uF306")
case "devuan":
return n.props.getString(Devuan, "\uF307")
case "raspbian":
return n.props.getString(Raspbian, "\uF315")
case "elementary":
return n.props.getString(Elementary, "\uF309")
case "fedora":
return n.props.getString(Fedora, "\uF30a")
case "gentoo":
return n.props.getString(Gentoo, "\uF30d")
case "mageia":
return n.props.getString(Mageia, "\uF310")
case "manjaro":
return n.props.getString(Manjaro, "\uF312")
case "mint":
return n.props.getString(Mint, "\uF30e")
case "nixos":
return n.props.getString(Nixos, "\uF313")
case "opensuse":
return n.props.getString(Opensuse, "\uF314")
case "sabayon":
return n.props.getString(Sabayon, "\uF317")
case "slackware":
return n.props.getString(Slackware, "\uF319")
case "ubuntu":
return n.props.getString(Ubuntu, "\uF31b")
}
return n.props.getString(Linux, "\uF17C")
}
2020-10-07 12:01:03 -07:00
func (n *osInfo) init(props *properties, env environmentInfo) {
n.props = props
n.env = env
2020-10-09 03:51:22 -07:00
}