mirror of
https://github.com/JanDeDobbeleer/oh-my-posh.git
synced 2024-12-28 04:19:41 -08:00
feat: add os segment
This commit is contained in:
parent
6e66501a0a
commit
59ed9c239f
31
docs/docs/segment-os.md
Normal file
31
docs/docs/segment-os.md
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
---
|
||||||
|
id: os
|
||||||
|
title: os
|
||||||
|
sidebar_label: OS
|
||||||
|
---
|
||||||
|
|
||||||
|
## What
|
||||||
|
|
||||||
|
Display OS specific info. Defaults to Icon.
|
||||||
|
|
||||||
|
## Sample Configuration
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"type": "os",
|
||||||
|
"style": "plain",
|
||||||
|
"foreground": "#26C6DA",
|
||||||
|
"background": "#546E7A",
|
||||||
|
"properties": {
|
||||||
|
"postfix": " ",
|
||||||
|
"macos": "mac"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Properties
|
||||||
|
|
||||||
|
- macos: `string` - the string to use for macOS - defaults to macOS icon
|
||||||
|
- linux: `string` - the icon to use for Linux - defaults to Linux icon
|
||||||
|
- windows: `string` - the icon to use for Windows - defaults to Windows icon
|
||||||
|
|
|
@ -19,6 +19,7 @@ module.exports = {
|
||||||
"exit",
|
"exit",
|
||||||
"git",
|
"git",
|
||||||
"node",
|
"node",
|
||||||
|
"os",
|
||||||
"path",
|
"path",
|
||||||
"python",
|
"python",
|
||||||
"root",
|
"root",
|
||||||
|
|
|
@ -56,6 +56,8 @@ const (
|
||||||
ShellInfo SegmentType = "shell"
|
ShellInfo SegmentType = "shell"
|
||||||
//Node writes which node version is currently active
|
//Node writes which node version is currently active
|
||||||
Node SegmentType = "node"
|
Node SegmentType = "node"
|
||||||
|
//OS write os specific icon
|
||||||
|
Os SegmentType = "os"
|
||||||
//Powerline writes it Powerline style
|
//Powerline writes it Powerline style
|
||||||
Powerline SegmentStyle = "powerline"
|
Powerline SegmentStyle = "powerline"
|
||||||
//Plain writes it without ornaments
|
//Plain writes it without ornaments
|
||||||
|
@ -107,6 +109,7 @@ func (segment *Segment) mapSegmentWithWriter(env environmentInfo) (*properties,
|
||||||
Spotify: &spotify{},
|
Spotify: &spotify{},
|
||||||
ShellInfo: &shell{},
|
ShellInfo: &shell{},
|
||||||
Node: &node{},
|
Node: &node{},
|
||||||
|
Os: &osInfo{},
|
||||||
}
|
}
|
||||||
if writer, ok := functions[segment.Type]; ok {
|
if writer, ok := functions[segment.Type]; ok {
|
||||||
props := &properties{
|
props := &properties{
|
||||||
|
|
38
segment_os.go
Normal file
38
segment_os.go
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
type osInfo struct {
|
||||||
|
props *properties
|
||||||
|
env environmentInfo
|
||||||
|
}
|
||||||
|
|
||||||
|
const (
|
||||||
|
//Macos the string to use for macOS
|
||||||
|
macOS Property = "macos"
|
||||||
|
//LinuxIcon the string to use for linux
|
||||||
|
Linux Property = "linux"
|
||||||
|
//WindowsIcon the icon to use for windows
|
||||||
|
Windows Property = "windows"
|
||||||
|
)
|
||||||
|
|
||||||
|
func (n *osInfo) enabled() bool {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
func (n *osInfo) string() string {
|
||||||
|
goos := n.env.getRuntimeGOOS()
|
||||||
|
switch goos {
|
||||||
|
case "windows":
|
||||||
|
return n.props.getString(Windows, "\uE62A")
|
||||||
|
case "darwin":
|
||||||
|
return n.props.getString(macOS, "\uF179")
|
||||||
|
case "linux":
|
||||||
|
return n.props.getString(Linux, "\uF17C")
|
||||||
|
default:
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (n *osInfo) init(props *properties, env environmentInfo) {
|
||||||
|
n.props = props
|
||||||
|
n.env = env
|
||||||
|
}
|
24
segment_os_test.go
Normal file
24
segment_os_test.go
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestOsInfo(t *testing.T) {
|
||||||
|
env := new(MockedEnvironment)
|
||||||
|
env.On("getRuntimeGOOS", nil).Return("windows")
|
||||||
|
props := &properties{
|
||||||
|
values: map[Property]interface{}{Windows: "win"},
|
||||||
|
foreground: "#fff",
|
||||||
|
background: "#000",
|
||||||
|
}
|
||||||
|
osInfo := &osInfo{
|
||||||
|
env: env,
|
||||||
|
props: props,
|
||||||
|
}
|
||||||
|
want := "win"
|
||||||
|
got := osInfo.string()
|
||||||
|
assert.Equal(t, want, got)
|
||||||
|
}
|
Loading…
Reference in a new issue