mirror of
https://github.com/JanDeDobbeleer/oh-my-posh.git
synced 2025-03-05 20:49:04 -08:00
feat(session): refactor for template
This commit is contained in:
parent
f00f5f9cf7
commit
a08a3a9a21
|
@ -36,7 +36,7 @@ sidebar_label: Sample
|
||||||
"leading_diamond": "\uE0B6",
|
"leading_diamond": "\uE0B6",
|
||||||
"trailing_diamond": "\uE0B0",
|
"trailing_diamond": "\uE0B0",
|
||||||
"properties": {
|
"properties": {
|
||||||
"postfix": " "
|
"template": "{{ .UserName }}"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
|
@ -17,37 +17,26 @@ Show the current user and host name.
|
||||||
"foreground": "#ffffff",
|
"foreground": "#ffffff",
|
||||||
"background": "#c386f1",
|
"background": "#c386f1",
|
||||||
"leading_diamond": "\uE0B6",
|
"leading_diamond": "\uE0B6",
|
||||||
"trailing_diamond": "\uE0B0"
|
"trailing_diamond": "\uE0B0",
|
||||||
|
"properties": {
|
||||||
|
"template": "{{ .UserName }}"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
## Properties
|
## Properties
|
||||||
|
|
||||||
- user_info_separator: `string` - text/icon to put in between the user and host name - defaults to `@`
|
|
||||||
- ssh_icon: `string` - text/icon to display first when in an active SSH session - defaults
|
- ssh_icon: `string` - text/icon to display first when in an active SSH session - defaults
|
||||||
to `\uF817 `
|
to `\uF817 `
|
||||||
- user_color: `string` [color][colors] - override the foreground color of the user name
|
|
||||||
- host_color: `string` [color][colors] - override the foreground color of the host name
|
|
||||||
- display_user: `boolean` - display the user name or not - defaults to `true`
|
|
||||||
- display_host: `boolean` - display the host name or not - defaults to `true`
|
|
||||||
- default_user_name: `string` - name of the default user - defaults to empty
|
|
||||||
- display_default: `boolean` - display the segment or not when the user matches `default_user_name` - defaults
|
|
||||||
to `true`
|
|
||||||
- template: `string` - A go [text/template][go-text-template] template extended with [sprig][sprig] utilizing the
|
- template: `string` - A go [text/template][go-text-template] template extended with [sprig][sprig] utilizing the
|
||||||
properties below. Only used when a value is set, making the above properties obsolete.
|
properties below.
|
||||||
|
|
||||||
## Template Properties
|
## Template Properties
|
||||||
|
|
||||||
- `.UserName`: `string` - the current user's name
|
- `.UserName`: `string` - the current user's name
|
||||||
- `.DefaultUserName`: - the default user name (set with the `POSH_SESSION_DEFAULT_USER` env var or `default_user_name` property)
|
|
||||||
- `.ComputerName`: `string` - the current computer's name
|
- `.ComputerName`: `string` - the current computer's name
|
||||||
- `.SSHSession`: `boolean` - active SSH session or not
|
- `.SSHSession`: `boolean` - active SSH session or not
|
||||||
- `.Root`: `boolean` - are you a root/admin user or not
|
- `.Root`: `boolean` - are you a root/admin user or not
|
||||||
|
|
||||||
## Environmnent Variables
|
|
||||||
|
|
||||||
- `POSH_SESSION_DEFAULT_USER` - used to override the hardcoded `default_user_name` property
|
|
||||||
|
|
||||||
[colors]: /docs/config-colors
|
|
||||||
[go-text-template]: https://golang.org/pkg/text/template/
|
[go-text-template]: https://golang.org/pkg/text/template/
|
||||||
[sprig]: https://masterminds.github.io/sprig/
|
[sprig]: https://masterminds.github.io/sprig/
|
||||||
|
|
|
@ -238,3 +238,69 @@ func (b *batt) shouldDisplay() bool {
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Session
|
||||||
|
|
||||||
|
const (
|
||||||
|
// UserInfoSeparator is put between the user and computer name
|
||||||
|
UserInfoSeparator Property = "user_info_separator"
|
||||||
|
// UserColor if set, is used to color the user name
|
||||||
|
UserColor Property = "user_color"
|
||||||
|
// HostColor if set, is used to color the computer name
|
||||||
|
HostColor Property = "host_color"
|
||||||
|
// DisplayHost hides or show the computer name
|
||||||
|
DisplayHost Property = "display_host"
|
||||||
|
// DisplayUser hides or shows the user name
|
||||||
|
DisplayUser Property = "display_user"
|
||||||
|
// DefaultUserName holds the default user of the platform
|
||||||
|
DefaultUserName Property = "default_user_name"
|
||||||
|
|
||||||
|
defaultUserEnvVar = "POSH_SESSION_DEFAULT_USER"
|
||||||
|
)
|
||||||
|
|
||||||
|
func (s *session) getDefaultUser() string {
|
||||||
|
user := s.env.getenv(defaultUserEnvVar)
|
||||||
|
if len(user) == 0 {
|
||||||
|
user = s.props.getString(DefaultUserName, "")
|
||||||
|
}
|
||||||
|
return user
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *session) legacyEnabled() bool {
|
||||||
|
if s.props.getBool(DisplayUser, true) {
|
||||||
|
s.UserName = s.getUserName()
|
||||||
|
}
|
||||||
|
if s.props.getBool(DisplayHost, true) {
|
||||||
|
s.ComputerName = s.getComputerName()
|
||||||
|
}
|
||||||
|
s.DefaultUserName = s.getDefaultUser()
|
||||||
|
showDefaultUser := s.props.getBool(DisplayDefault, true)
|
||||||
|
if !showDefaultUser && s.DefaultUserName == s.UserName {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *session) getFormattedText() string {
|
||||||
|
separator := ""
|
||||||
|
if s.props.getBool(DisplayHost, true) && s.props.getBool(DisplayUser, true) {
|
||||||
|
separator = s.props.getString(UserInfoSeparator, "@")
|
||||||
|
}
|
||||||
|
var sshIcon string
|
||||||
|
if s.SSHSession {
|
||||||
|
sshIcon = s.props.getString(SSHIcon, "\uF817 ")
|
||||||
|
}
|
||||||
|
defaulColor := s.props.getColor(ForegroundOverride, "")
|
||||||
|
userColor := s.props.getColor(UserColor, defaulColor)
|
||||||
|
hostColor := s.props.getColor(HostColor, defaulColor)
|
||||||
|
if len(userColor) > 0 && len(hostColor) > 0 {
|
||||||
|
return fmt.Sprintf("%s<%s>%s</>%s<%s>%s</>", sshIcon, userColor, s.UserName, separator, hostColor, s.ComputerName)
|
||||||
|
}
|
||||||
|
if len(userColor) > 0 {
|
||||||
|
return fmt.Sprintf("%s<%s>%s</>%s%s", sshIcon, userColor, s.UserName, separator, s.ComputerName)
|
||||||
|
}
|
||||||
|
if len(hostColor) > 0 {
|
||||||
|
return fmt.Sprintf("%s%s%s<%s>%s</>", sshIcon, s.UserName, separator, hostColor, s.ComputerName)
|
||||||
|
}
|
||||||
|
return fmt.Sprintf("%s%s%s%s", sshIcon, s.UserName, separator, s.ComputerName)
|
||||||
|
}
|
||||||
|
|
|
@ -401,3 +401,198 @@ func TestBatterySegmentSingle(t *testing.T) {
|
||||||
assert.Equal(t, tc.ExpectedColor, actualColor, tc.Case)
|
assert.Equal(t, tc.ExpectedColor, actualColor, tc.Case)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Session
|
||||||
|
|
||||||
|
func TestPropertySessionSegment(t *testing.T) {
|
||||||
|
cases := []struct {
|
||||||
|
Case string
|
||||||
|
ExpectedEnabled bool
|
||||||
|
ExpectedString string
|
||||||
|
UserName string
|
||||||
|
Host string
|
||||||
|
DefaultUserName string
|
||||||
|
DefaultUserNameEnv string
|
||||||
|
SSHSession bool
|
||||||
|
SSHClient bool
|
||||||
|
Root bool
|
||||||
|
DisplayUser bool
|
||||||
|
DisplayHost bool
|
||||||
|
DisplayDefault bool
|
||||||
|
HostColor string
|
||||||
|
UserColor string
|
||||||
|
GOOS string
|
||||||
|
HostError bool
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
Case: "user and computer",
|
||||||
|
ExpectedString: "john at company-laptop",
|
||||||
|
Host: "company-laptop",
|
||||||
|
DisplayUser: true,
|
||||||
|
DisplayHost: true,
|
||||||
|
UserName: "john",
|
||||||
|
ExpectedEnabled: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Case: "user and computer with host color",
|
||||||
|
ExpectedString: "john at <yellow>company-laptop</>",
|
||||||
|
Host: "company-laptop",
|
||||||
|
DisplayUser: true,
|
||||||
|
DisplayHost: true,
|
||||||
|
UserName: "john",
|
||||||
|
HostColor: "yellow",
|
||||||
|
ExpectedEnabled: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Case: "user and computer with user color",
|
||||||
|
ExpectedString: "<yellow>john</> at company-laptop",
|
||||||
|
Host: "company-laptop",
|
||||||
|
DisplayUser: true,
|
||||||
|
DisplayHost: true,
|
||||||
|
UserName: "john",
|
||||||
|
UserColor: "yellow",
|
||||||
|
ExpectedEnabled: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Case: "user and computer with both colors",
|
||||||
|
ExpectedString: "<yellow>john</> at <green>company-laptop</>",
|
||||||
|
Host: "company-laptop",
|
||||||
|
DisplayUser: true,
|
||||||
|
DisplayHost: true,
|
||||||
|
UserName: "john",
|
||||||
|
UserColor: "yellow",
|
||||||
|
HostColor: "green",
|
||||||
|
ExpectedEnabled: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Case: "SSH Session",
|
||||||
|
ExpectedString: "ssh john at company-laptop",
|
||||||
|
Host: "company-laptop",
|
||||||
|
DisplayUser: true,
|
||||||
|
DisplayHost: true,
|
||||||
|
UserName: "john",
|
||||||
|
SSHSession: true,
|
||||||
|
ExpectedEnabled: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Case: "SSH Client",
|
||||||
|
ExpectedString: "ssh john at company-laptop",
|
||||||
|
Host: "company-laptop",
|
||||||
|
DisplayUser: true,
|
||||||
|
DisplayHost: true,
|
||||||
|
UserName: "john",
|
||||||
|
SSHClient: true,
|
||||||
|
ExpectedEnabled: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Case: "SSH Client",
|
||||||
|
ExpectedString: "ssh john at company-laptop",
|
||||||
|
Host: "company-laptop",
|
||||||
|
DisplayUser: true,
|
||||||
|
DisplayHost: true,
|
||||||
|
UserName: "john",
|
||||||
|
SSHClient: true,
|
||||||
|
ExpectedEnabled: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Case: "only user name",
|
||||||
|
ExpectedString: "john",
|
||||||
|
Host: "company-laptop",
|
||||||
|
UserName: "john",
|
||||||
|
DisplayUser: true,
|
||||||
|
ExpectedEnabled: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Case: "windows user name",
|
||||||
|
ExpectedString: "john at company-laptop",
|
||||||
|
Host: "company-laptop",
|
||||||
|
UserName: "surface\\john",
|
||||||
|
DisplayHost: true,
|
||||||
|
DisplayUser: true,
|
||||||
|
ExpectedEnabled: true,
|
||||||
|
GOOS: string(Windows),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Case: "only host name",
|
||||||
|
ExpectedString: "company-laptop",
|
||||||
|
Host: "company-laptop",
|
||||||
|
UserName: "john",
|
||||||
|
DisplayDefault: true,
|
||||||
|
DisplayHost: true,
|
||||||
|
ExpectedEnabled: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Case: "display default - hidden",
|
||||||
|
Host: "company-laptop",
|
||||||
|
UserName: "john",
|
||||||
|
DefaultUserName: "john",
|
||||||
|
DisplayDefault: false,
|
||||||
|
DisplayHost: true,
|
||||||
|
DisplayUser: true,
|
||||||
|
ExpectedEnabled: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Case: "display default with env var - hidden",
|
||||||
|
Host: "company-laptop",
|
||||||
|
UserName: "john",
|
||||||
|
DefaultUserNameEnv: "john",
|
||||||
|
DefaultUserName: "jake",
|
||||||
|
DisplayDefault: false,
|
||||||
|
DisplayHost: true,
|
||||||
|
DisplayUser: true,
|
||||||
|
ExpectedEnabled: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Case: "host error",
|
||||||
|
ExpectedString: "john at unknown",
|
||||||
|
Host: "company-laptop",
|
||||||
|
HostError: true,
|
||||||
|
UserName: "john",
|
||||||
|
DisplayHost: true,
|
||||||
|
DisplayUser: true,
|
||||||
|
ExpectedEnabled: true,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, tc := range cases {
|
||||||
|
env := new(MockedEnvironment)
|
||||||
|
env.On("getCurrentUser", nil).Return(tc.UserName)
|
||||||
|
env.On("getRuntimeGOOS", nil).Return(tc.GOOS)
|
||||||
|
if tc.HostError {
|
||||||
|
env.On("getHostName", nil).Return(tc.Host, errors.New("oh snap"))
|
||||||
|
} else {
|
||||||
|
env.On("getHostName", nil).Return(tc.Host, nil)
|
||||||
|
}
|
||||||
|
var SSHSession string
|
||||||
|
if tc.SSHSession {
|
||||||
|
SSHSession = "zezzion"
|
||||||
|
}
|
||||||
|
var SSHClient string
|
||||||
|
if tc.SSHClient {
|
||||||
|
SSHClient = "clientz"
|
||||||
|
}
|
||||||
|
env.On("getenv", "SSH_CONNECTION").Return(SSHSession)
|
||||||
|
env.On("getenv", "SSH_CLIENT").Return(SSHClient)
|
||||||
|
env.On("getenv", "SSH_CLIENT").Return(SSHSession)
|
||||||
|
env.On("getenv", defaultUserEnvVar).Return(tc.DefaultUserNameEnv)
|
||||||
|
env.On("isRunningAsRoot", nil).Return(tc.Root)
|
||||||
|
var props properties = map[Property]interface{}{
|
||||||
|
UserInfoSeparator: " at ",
|
||||||
|
SSHIcon: "ssh ",
|
||||||
|
DefaultUserName: tc.DefaultUserName,
|
||||||
|
DisplayDefault: tc.DisplayDefault,
|
||||||
|
DisplayUser: tc.DisplayUser,
|
||||||
|
DisplayHost: tc.DisplayHost,
|
||||||
|
HostColor: tc.HostColor,
|
||||||
|
UserColor: tc.UserColor,
|
||||||
|
}
|
||||||
|
session := &session{
|
||||||
|
env: env,
|
||||||
|
props: props,
|
||||||
|
}
|
||||||
|
assert.Equal(t, tc.ExpectedEnabled, session.enabled(), tc.Case)
|
||||||
|
if tc.ExpectedEnabled {
|
||||||
|
assert.Equal(t, tc.ExpectedString, session.string(), tc.Case)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -1,68 +1,51 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import "strings"
|
||||||
"fmt"
|
|
||||||
"strings"
|
|
||||||
)
|
|
||||||
|
|
||||||
type session struct {
|
type session struct {
|
||||||
props properties
|
props properties
|
||||||
env environmentInfo
|
env environmentInfo
|
||||||
UserName string
|
text string
|
||||||
|
|
||||||
|
UserName string
|
||||||
|
ComputerName string
|
||||||
|
SSHSession bool
|
||||||
|
Root bool
|
||||||
|
|
||||||
DefaultUserName string
|
DefaultUserName string
|
||||||
ComputerName string
|
|
||||||
SSHSession bool
|
|
||||||
Root bool
|
|
||||||
templateText string
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
// UserInfoSeparator is put between the user and computer name
|
// SSHIcon is the icon used for SSH sessions
|
||||||
UserInfoSeparator Property = "user_info_separator"
|
|
||||||
// UserColor if set, is used to color the user name
|
|
||||||
UserColor Property = "user_color"
|
|
||||||
// HostColor if set, is used to color the computer name
|
|
||||||
HostColor Property = "host_color"
|
|
||||||
// DisplayHost hides or show the computer name
|
|
||||||
DisplayHost Property = "display_host"
|
|
||||||
// DisplayUser hides or shows the user name
|
|
||||||
DisplayUser Property = "display_user"
|
|
||||||
// SSHIcon shows when in an SSH session
|
|
||||||
SSHIcon Property = "ssh_icon"
|
SSHIcon Property = "ssh_icon"
|
||||||
// DefaultUserName holds the default user of the platform
|
|
||||||
DefaultUserName Property = "default_user_name"
|
|
||||||
|
|
||||||
defaultUserEnvVar = "POSH_SESSION_DEFAULT_USER"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func (s *session) enabled() bool {
|
func (s *session) enabled() bool {
|
||||||
|
s.SSHSession = s.activeSSHSession()
|
||||||
|
segmentTemplate := s.props.getString(SegmentTemplate, "")
|
||||||
|
if segmentTemplate == "" {
|
||||||
|
return s.legacyEnabled()
|
||||||
|
}
|
||||||
s.UserName = s.getUserName()
|
s.UserName = s.getUserName()
|
||||||
s.ComputerName = s.getComputerName()
|
s.ComputerName = s.getComputerName()
|
||||||
s.SSHSession = s.activeSSHSession()
|
s.Root = s.env.isRunningAsRoot()
|
||||||
s.DefaultUserName = s.getDefaultUser()
|
template := &textTemplate{
|
||||||
segmentTemplate := s.props.getString(SegmentTemplate, "")
|
Template: segmentTemplate,
|
||||||
if segmentTemplate != "" {
|
Context: s,
|
||||||
s.Root = s.env.isRunningAsRoot()
|
Env: s.env,
|
||||||
template := &textTemplate{
|
|
||||||
Template: segmentTemplate,
|
|
||||||
Context: s,
|
|
||||||
Env: s.env,
|
|
||||||
}
|
|
||||||
var err error
|
|
||||||
s.templateText, err = template.render()
|
|
||||||
if err != nil {
|
|
||||||
s.templateText = err.Error()
|
|
||||||
}
|
|
||||||
return len(s.templateText) > 0
|
|
||||||
}
|
}
|
||||||
showDefaultUser := s.props.getBool(DisplayDefault, true)
|
var err error
|
||||||
if !showDefaultUser && s.DefaultUserName == s.UserName {
|
s.text, err = template.render()
|
||||||
return false
|
if err != nil {
|
||||||
|
s.text = err.Error()
|
||||||
}
|
}
|
||||||
return true
|
return len(s.text) > 0
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *session) string() string {
|
func (s *session) string() string {
|
||||||
|
if len(s.text) != 0 {
|
||||||
|
return s.text
|
||||||
|
}
|
||||||
return s.getFormattedText()
|
return s.getFormattedText()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -71,48 +54,7 @@ func (s *session) init(props properties, env environmentInfo) {
|
||||||
s.env = env
|
s.env = env
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *session) getFormattedText() string {
|
|
||||||
if len(s.templateText) > 0 {
|
|
||||||
return s.templateText
|
|
||||||
}
|
|
||||||
separator := ""
|
|
||||||
if s.props.getBool(DisplayHost, true) && s.props.getBool(DisplayUser, true) {
|
|
||||||
separator = s.props.getString(UserInfoSeparator, "@")
|
|
||||||
}
|
|
||||||
var sshIcon string
|
|
||||||
if s.SSHSession {
|
|
||||||
sshIcon = s.props.getString(SSHIcon, "\uF817 ")
|
|
||||||
}
|
|
||||||
defaulColor := s.props.getColor(ForegroundOverride, "")
|
|
||||||
userColor := s.props.getColor(UserColor, defaulColor)
|
|
||||||
hostColor := s.props.getColor(HostColor, defaulColor)
|
|
||||||
if len(userColor) > 0 && len(hostColor) > 0 {
|
|
||||||
return fmt.Sprintf("%s<%s>%s</>%s<%s>%s</>", sshIcon, userColor, s.UserName, separator, hostColor, s.ComputerName)
|
|
||||||
}
|
|
||||||
if len(userColor) > 0 {
|
|
||||||
return fmt.Sprintf("%s<%s>%s</>%s%s", sshIcon, userColor, s.UserName, separator, s.ComputerName)
|
|
||||||
}
|
|
||||||
if len(hostColor) > 0 {
|
|
||||||
return fmt.Sprintf("%s%s%s<%s>%s</>", sshIcon, s.UserName, separator, hostColor, s.ComputerName)
|
|
||||||
}
|
|
||||||
return fmt.Sprintf("%s%s%s%s", sshIcon, s.UserName, separator, s.ComputerName)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *session) getComputerName() string {
|
|
||||||
if !s.props.getBool(DisplayHost, true) {
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
computername, err := s.env.getHostName()
|
|
||||||
if err != nil {
|
|
||||||
computername = "unknown"
|
|
||||||
}
|
|
||||||
return strings.TrimSpace(computername)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *session) getUserName() string {
|
func (s *session) getUserName() string {
|
||||||
if !s.props.getBool(DisplayUser, true) {
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
user := s.env.getCurrentUser()
|
user := s.env.getCurrentUser()
|
||||||
username := strings.TrimSpace(user)
|
username := strings.TrimSpace(user)
|
||||||
if s.env.getRuntimeGOOS() == "windows" && strings.Contains(username, "\\") {
|
if s.env.getRuntimeGOOS() == "windows" && strings.Contains(username, "\\") {
|
||||||
|
@ -121,12 +63,12 @@ func (s *session) getUserName() string {
|
||||||
return username
|
return username
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *session) getDefaultUser() string {
|
func (s *session) getComputerName() string {
|
||||||
user := s.env.getenv(defaultUserEnvVar)
|
computername, err := s.env.getHostName()
|
||||||
if len(user) == 0 {
|
if err != nil {
|
||||||
user = s.props.getString(DefaultUserName, "")
|
computername = "unknown"
|
||||||
}
|
}
|
||||||
return user
|
return strings.TrimSpace(computername)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *session) activeSSHSession() bool {
|
func (s *session) activeSSHSession() bool {
|
||||||
|
|
|
@ -1,205 +1,11 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestPropertySessionSegment(t *testing.T) {
|
|
||||||
cases := []struct {
|
|
||||||
Case string
|
|
||||||
ExpectedEnabled bool
|
|
||||||
ExpectedString string
|
|
||||||
UserName string
|
|
||||||
Host string
|
|
||||||
DefaultUserName string
|
|
||||||
DefaultUserNameEnv string
|
|
||||||
SSHSession bool
|
|
||||||
SSHClient bool
|
|
||||||
Root bool
|
|
||||||
DisplayUser bool
|
|
||||||
DisplayHost bool
|
|
||||||
DisplayDefault bool
|
|
||||||
HostColor string
|
|
||||||
UserColor string
|
|
||||||
GOOS string
|
|
||||||
HostError bool
|
|
||||||
}{
|
|
||||||
{
|
|
||||||
Case: "user and computer",
|
|
||||||
ExpectedString: "john at company-laptop",
|
|
||||||
Host: "company-laptop",
|
|
||||||
DisplayUser: true,
|
|
||||||
DisplayHost: true,
|
|
||||||
UserName: "john",
|
|
||||||
ExpectedEnabled: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Case: "user and computer with host color",
|
|
||||||
ExpectedString: "john at <yellow>company-laptop</>",
|
|
||||||
Host: "company-laptop",
|
|
||||||
DisplayUser: true,
|
|
||||||
DisplayHost: true,
|
|
||||||
UserName: "john",
|
|
||||||
HostColor: "yellow",
|
|
||||||
ExpectedEnabled: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Case: "user and computer with user color",
|
|
||||||
ExpectedString: "<yellow>john</> at company-laptop",
|
|
||||||
Host: "company-laptop",
|
|
||||||
DisplayUser: true,
|
|
||||||
DisplayHost: true,
|
|
||||||
UserName: "john",
|
|
||||||
UserColor: "yellow",
|
|
||||||
ExpectedEnabled: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Case: "user and computer with both colors",
|
|
||||||
ExpectedString: "<yellow>john</> at <green>company-laptop</>",
|
|
||||||
Host: "company-laptop",
|
|
||||||
DisplayUser: true,
|
|
||||||
DisplayHost: true,
|
|
||||||
UserName: "john",
|
|
||||||
UserColor: "yellow",
|
|
||||||
HostColor: "green",
|
|
||||||
ExpectedEnabled: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Case: "SSH Session",
|
|
||||||
ExpectedString: "ssh john at company-laptop",
|
|
||||||
Host: "company-laptop",
|
|
||||||
DisplayUser: true,
|
|
||||||
DisplayHost: true,
|
|
||||||
UserName: "john",
|
|
||||||
SSHSession: true,
|
|
||||||
ExpectedEnabled: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Case: "SSH Client",
|
|
||||||
ExpectedString: "ssh john at company-laptop",
|
|
||||||
Host: "company-laptop",
|
|
||||||
DisplayUser: true,
|
|
||||||
DisplayHost: true,
|
|
||||||
UserName: "john",
|
|
||||||
SSHClient: true,
|
|
||||||
ExpectedEnabled: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Case: "SSH Client",
|
|
||||||
ExpectedString: "ssh john at company-laptop",
|
|
||||||
Host: "company-laptop",
|
|
||||||
DisplayUser: true,
|
|
||||||
DisplayHost: true,
|
|
||||||
UserName: "john",
|
|
||||||
SSHClient: true,
|
|
||||||
ExpectedEnabled: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Case: "only user name",
|
|
||||||
ExpectedString: "john",
|
|
||||||
Host: "company-laptop",
|
|
||||||
UserName: "john",
|
|
||||||
DisplayUser: true,
|
|
||||||
ExpectedEnabled: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Case: "windows user name",
|
|
||||||
ExpectedString: "john at company-laptop",
|
|
||||||
Host: "company-laptop",
|
|
||||||
UserName: "surface\\john",
|
|
||||||
DisplayHost: true,
|
|
||||||
DisplayUser: true,
|
|
||||||
ExpectedEnabled: true,
|
|
||||||
GOOS: string(Windows),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Case: "only host name",
|
|
||||||
ExpectedString: "company-laptop",
|
|
||||||
Host: "company-laptop",
|
|
||||||
UserName: "john",
|
|
||||||
DisplayDefault: true,
|
|
||||||
DisplayHost: true,
|
|
||||||
ExpectedEnabled: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Case: "display default - hidden",
|
|
||||||
Host: "company-laptop",
|
|
||||||
UserName: "john",
|
|
||||||
DefaultUserName: "john",
|
|
||||||
DisplayDefault: false,
|
|
||||||
DisplayHost: true,
|
|
||||||
DisplayUser: true,
|
|
||||||
ExpectedEnabled: false,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Case: "display default with env var - hidden",
|
|
||||||
Host: "company-laptop",
|
|
||||||
UserName: "john",
|
|
||||||
DefaultUserNameEnv: "john",
|
|
||||||
DefaultUserName: "jake",
|
|
||||||
DisplayDefault: false,
|
|
||||||
DisplayHost: true,
|
|
||||||
DisplayUser: true,
|
|
||||||
ExpectedEnabled: false,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Case: "host error",
|
|
||||||
ExpectedString: "john at unknown",
|
|
||||||
Host: "company-laptop",
|
|
||||||
HostError: true,
|
|
||||||
UserName: "john",
|
|
||||||
DisplayHost: true,
|
|
||||||
DisplayUser: true,
|
|
||||||
ExpectedEnabled: true,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, tc := range cases {
|
|
||||||
env := new(MockedEnvironment)
|
|
||||||
env.On("getCurrentUser", nil).Return(tc.UserName)
|
|
||||||
env.On("getRuntimeGOOS", nil).Return(tc.GOOS)
|
|
||||||
if tc.HostError {
|
|
||||||
env.On("getHostName", nil).Return(tc.Host, errors.New("oh snap"))
|
|
||||||
} else {
|
|
||||||
env.On("getHostName", nil).Return(tc.Host, nil)
|
|
||||||
}
|
|
||||||
var SSHSession string
|
|
||||||
if tc.SSHSession {
|
|
||||||
SSHSession = "zezzion"
|
|
||||||
}
|
|
||||||
var SSHClient string
|
|
||||||
if tc.SSHClient {
|
|
||||||
SSHClient = "clientz"
|
|
||||||
}
|
|
||||||
env.On("getenv", "SSH_CONNECTION").Return(SSHSession)
|
|
||||||
env.On("getenv", "SSH_CLIENT").Return(SSHClient)
|
|
||||||
env.On("getenv", "SSH_CLIENT").Return(SSHSession)
|
|
||||||
env.On("getenv", defaultUserEnvVar).Return(tc.DefaultUserNameEnv)
|
|
||||||
env.On("isRunningAsRoot", nil).Return(tc.Root)
|
|
||||||
var props properties = map[Property]interface{}{
|
|
||||||
UserInfoSeparator: " at ",
|
|
||||||
SSHIcon: "ssh ",
|
|
||||||
DefaultUserName: tc.DefaultUserName,
|
|
||||||
DisplayDefault: tc.DisplayDefault,
|
|
||||||
DisplayUser: tc.DisplayUser,
|
|
||||||
DisplayHost: tc.DisplayHost,
|
|
||||||
HostColor: tc.HostColor,
|
|
||||||
UserColor: tc.UserColor,
|
|
||||||
}
|
|
||||||
session := &session{
|
|
||||||
env: env,
|
|
||||||
props: props,
|
|
||||||
}
|
|
||||||
assert.Equal(t, tc.ExpectedEnabled, session.enabled(), tc.Case)
|
|
||||||
if tc.ExpectedEnabled {
|
|
||||||
assert.Equal(t, tc.ExpectedString, session.string(), tc.Case)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestSessionSegmentTemplate(t *testing.T) {
|
func TestSessionSegmentTemplate(t *testing.T) {
|
||||||
cases := []struct {
|
cases := []struct {
|
||||||
Case string
|
Case string
|
||||||
|
@ -217,14 +23,14 @@ func TestSessionSegmentTemplate(t *testing.T) {
|
||||||
ExpectedString: "john@company-laptop",
|
ExpectedString: "john@company-laptop",
|
||||||
ComputerName: "company-laptop",
|
ComputerName: "company-laptop",
|
||||||
UserName: "john",
|
UserName: "john",
|
||||||
Template: "{{.UserName}}{{if .ComputerName}}@{{.ComputerName}}{{end}}",
|
Template: "{{.UserName}}@{{.ComputerName}}",
|
||||||
ExpectedEnabled: true,
|
ExpectedEnabled: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Case: "user only",
|
Case: "user only",
|
||||||
ExpectedString: "john",
|
ExpectedString: "john",
|
||||||
UserName: "john",
|
UserName: "john",
|
||||||
Template: "{{.UserName}}{{if .ComputerName}}@{{.ComputerName}}{{end}}",
|
Template: "{{.UserName}}",
|
||||||
ExpectedEnabled: true,
|
ExpectedEnabled: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -272,7 +78,7 @@ func TestSessionSegmentTemplate(t *testing.T) {
|
||||||
SSHSession: true,
|
SSHSession: true,
|
||||||
ComputerName: "remote",
|
ComputerName: "remote",
|
||||||
Root: true,
|
Root: true,
|
||||||
Template: "{{if ne .DefaultUserName .UserName}}{{.UserName}}{{end}}",
|
Template: "{{if ne .Env.POSH_SESSION_DEFAULT_USER .UserName}}{{.UserName}}{{end}}",
|
||||||
ExpectedEnabled: true,
|
ExpectedEnabled: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -283,7 +89,7 @@ func TestSessionSegmentTemplate(t *testing.T) {
|
||||||
SSHSession: true,
|
SSHSession: true,
|
||||||
ComputerName: "remote",
|
ComputerName: "remote",
|
||||||
Root: true,
|
Root: true,
|
||||||
Template: "{{if ne .DefaultUserName .UserName}}{{.UserName}}{{end}}",
|
Template: "{{if ne .Env.POSH_SESSION_DEFAULT_USER .UserName}}{{.UserName}}{{end}}",
|
||||||
ExpectedEnabled: false,
|
ExpectedEnabled: false,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,8 +43,7 @@
|
||||||
"leading_diamond": "",
|
"leading_diamond": "",
|
||||||
"trailing_diamond": "\uE0B0",
|
"trailing_diamond": "\uE0B0",
|
||||||
"properties": {
|
"properties": {
|
||||||
"postfix": " ",
|
"template": "{{ .UserName }}"
|
||||||
"display_host": false
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
|
@ -12,8 +12,7 @@
|
||||||
"leading_diamond": "",
|
"leading_diamond": "",
|
||||||
"trailing_diamond": "\uE0B0",
|
"trailing_diamond": "\uE0B0",
|
||||||
"properties": {
|
"properties": {
|
||||||
"postfix": " ",
|
"template": "{{ .UserName }}"
|
||||||
"display_host": false
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
"trailing_diamond": "",
|
"trailing_diamond": "",
|
||||||
"properties": {
|
"properties": {
|
||||||
"prefix": "",
|
"prefix": "",
|
||||||
"display_host": false
|
"template": "{{ .UserName }}"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
|
@ -17,7 +17,10 @@
|
||||||
"style": "powerline",
|
"style": "powerline",
|
||||||
"powerline_symbol": "\uE0B0",
|
"powerline_symbol": "\uE0B0",
|
||||||
"foreground": "#100e23",
|
"foreground": "#100e23",
|
||||||
"background": "#ffffff"
|
"background": "#ffffff",
|
||||||
|
"properties": {
|
||||||
|
"template": "{{ .UserName }}@{{ .ComputerName }}"
|
||||||
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"type": "path",
|
"type": "path",
|
||||||
|
|
|
@ -26,7 +26,10 @@
|
||||||
"style": "powerline",
|
"style": "powerline",
|
||||||
"powerline_symbol": "\uE0B0",
|
"powerline_symbol": "\uE0B0",
|
||||||
"foreground": "#100e23",
|
"foreground": "#100e23",
|
||||||
"background": "#ffffff"
|
"background": "#ffffff",
|
||||||
|
"properties": {
|
||||||
|
"template": "{{ .UserName }}@{{ .ComputerName }}"
|
||||||
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"type": "path",
|
"type": "path",
|
||||||
|
|
|
@ -11,7 +11,10 @@
|
||||||
"foreground": "#ffffff",
|
"foreground": "#ffffff",
|
||||||
"background": "#61AFEF",
|
"background": "#61AFEF",
|
||||||
"leading_diamond": "\uE0B6",
|
"leading_diamond": "\uE0B6",
|
||||||
"trailing_diamond": "\uE0B0"
|
"trailing_diamond": "\uE0B0",
|
||||||
|
"properties": {
|
||||||
|
"template": "{{ .UserName }}@{{ .ComputerName }}"
|
||||||
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"type": "path",
|
"type": "path",
|
||||||
|
|
|
@ -10,9 +10,9 @@
|
||||||
"style": "plain",
|
"style": "plain",
|
||||||
"foreground": "#45F1C2",
|
"foreground": "#45F1C2",
|
||||||
"properties": {
|
"properties": {
|
||||||
"display_host": false,
|
|
||||||
"prefix": "\uf508 ",
|
"prefix": "\uf508 ",
|
||||||
"postfix": " on"
|
"postfix": " on",
|
||||||
|
"template": "{{ .UserName }}"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
|
@ -11,11 +11,9 @@
|
||||||
"type": "session",
|
"type": "session",
|
||||||
"style": "plain",
|
"style": "plain",
|
||||||
"properties": {
|
"properties": {
|
||||||
"user_info_separator": "<#ff5555>@</>",
|
|
||||||
"prefix": "╭─[",
|
"prefix": "╭─[",
|
||||||
"postfix": "]─",
|
"postfix": "]─",
|
||||||
"user_color": "#ffff55",
|
"template": "<#ffff55>{{ .UserName }}</><#ff5555>@</><#55ff55>{{ .ComputerName }}</>"
|
||||||
"host_color": "#55ff55"
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
|
@ -101,7 +101,7 @@
|
||||||
"properties": {
|
"properties": {
|
||||||
"postfix": "",
|
"postfix": "",
|
||||||
"prefix": " ",
|
"prefix": " ",
|
||||||
"user_info_separator": "<transparent> / </>"
|
"template": "{{ .UserName }}<transparent> / </>{{ .ComputerName }}"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
|
@ -22,7 +22,10 @@
|
||||||
"style": "powerline",
|
"style": "powerline",
|
||||||
"foreground": "#26C6DA",
|
"foreground": "#26C6DA",
|
||||||
"background": "#546E7A",
|
"background": "#546E7A",
|
||||||
"powerline_symbol": "\uE0B0"
|
"powerline_symbol": "\uE0B0",
|
||||||
|
"properties": {
|
||||||
|
"template": "{{ .UserName }}@{{ .ComputerName }}"
|
||||||
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"type": "battery",
|
"type": "battery",
|
||||||
|
|
|
@ -14,9 +14,9 @@
|
||||||
"foreground": "#E64747",
|
"foreground": "#E64747",
|
||||||
"background": "#29315A",
|
"background": "#29315A",
|
||||||
"properties": {
|
"properties": {
|
||||||
"display_host": false,
|
|
||||||
"postfix": "",
|
"postfix": "",
|
||||||
"prefix": ""
|
"prefix": "",
|
||||||
|
"template": "{{ .UserName }}"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
|
@ -144,9 +144,9 @@
|
||||||
"foreground": "#9B6BDF",
|
"foreground": "#9B6BDF",
|
||||||
"background": "#424242",
|
"background": "#424242",
|
||||||
"properties": {
|
"properties": {
|
||||||
"display_host": false,
|
|
||||||
"postfix": " \u276F",
|
"postfix": " \u276F",
|
||||||
"prefix": ""
|
"prefix": "",
|
||||||
|
"template": "{{ .UserName }}"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
|
@ -13,10 +13,9 @@
|
||||||
"background": "#E36464",
|
"background": "#E36464",
|
||||||
"foreground": "#fff",
|
"foreground": "#fff",
|
||||||
"properties": {
|
"properties": {
|
||||||
"user_info_separator": "",
|
|
||||||
"display_host": false,
|
|
||||||
"prefix": "",
|
"prefix": "",
|
||||||
"postfix": " "
|
"postfix": " ",
|
||||||
|
"template": "{{ .UserName }}"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
|
@ -10,7 +10,10 @@
|
||||||
"style": "diamond",
|
"style": "diamond",
|
||||||
"foreground": "#ffffff",
|
"foreground": "#ffffff",
|
||||||
"background": "#07585c",
|
"background": "#07585c",
|
||||||
"leading_diamond": "\uE0B6"
|
"leading_diamond": "\uE0B6",
|
||||||
|
"properties": {
|
||||||
|
"template": "{{ .UserName }}@{{ .ComputerName }}"
|
||||||
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"type": "path",
|
"type": "path",
|
||||||
|
|
|
@ -10,10 +10,9 @@
|
||||||
"style": "plain",
|
"style": "plain",
|
||||||
"foreground": "#ffffff",
|
"foreground": "#ffffff",
|
||||||
"properties": {
|
"properties": {
|
||||||
"user_info_separator": "",
|
|
||||||
"display_host": false,
|
|
||||||
"prefix": "<#CB4B16>┏[</>",
|
"prefix": "<#CB4B16>┏[</>",
|
||||||
"postfix": "<#CB4B16>]</>"
|
"postfix": "<#CB4B16>]</>",
|
||||||
|
"template": "{{ .UserName }}"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
"trailing_diamond": "",
|
"trailing_diamond": "",
|
||||||
"properties": {
|
"properties": {
|
||||||
"prefix": "",
|
"prefix": "",
|
||||||
"display_host": false
|
"template": "{{ .UserName }}"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
|
@ -22,7 +22,10 @@
|
||||||
{
|
{
|
||||||
"type": "session",
|
"type": "session",
|
||||||
"style": "plain",
|
"style": "plain",
|
||||||
"foreground": "#ffffff"
|
"foreground": "#ffffff",
|
||||||
|
"properties": {
|
||||||
|
"template": "{{ .UserName }}@{{ .ComputerName }}"
|
||||||
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"type": "path",
|
"type": "path",
|
||||||
|
|
|
@ -16,7 +16,10 @@
|
||||||
"type": "session",
|
"type": "session",
|
||||||
"style": "powerline",
|
"style": "powerline",
|
||||||
"foreground": "#ffffff",
|
"foreground": "#ffffff",
|
||||||
"background": "#3A86FF"
|
"background": "#3A86FF",
|
||||||
|
"properties": {
|
||||||
|
"template": "{{ .UserName }}@{{ .ComputerName }}"
|
||||||
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"type": "path",
|
"type": "path",
|
||||||
|
|
|
@ -10,8 +10,8 @@
|
||||||
"style": "plain",
|
"style": "plain",
|
||||||
"foreground": "#7E46B6",
|
"foreground": "#7E46B6",
|
||||||
"properties": {
|
"properties": {
|
||||||
"display_host": false,
|
"prefix": "",
|
||||||
"prefix": ""
|
"template": "{{ .UserName }}"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
|
@ -10,10 +10,8 @@
|
||||||
"style": "plain",
|
"style": "plain",
|
||||||
"foreground": "#FFFFFF",
|
"foreground": "#FFFFFF",
|
||||||
"properties": {
|
"properties": {
|
||||||
"user_info_separator": " <#ffffff>in</> ",
|
|
||||||
"prefix": "<#0377C8># </>",
|
"prefix": "<#0377C8># </>",
|
||||||
"user_color": "#0377C8",
|
"template": "<#0377C8>{{ .UserName }}</> <#ffffff>in</> <#4A9207>{{ .ComputerName }}</>"
|
||||||
"host_color": "#4A9207"
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
|
@ -109,9 +109,7 @@
|
||||||
"foreground": "#ffffff",
|
"foreground": "#ffffff",
|
||||||
"background": "#86BBD8",
|
"background": "#86BBD8",
|
||||||
"properties": {
|
"properties": {
|
||||||
"prefix": " ",
|
"template": "{{ .UserName }}"
|
||||||
"postfix": " ",
|
|
||||||
"display_host": false
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
|
@ -10,10 +10,9 @@
|
||||||
"style": "plain",
|
"style": "plain",
|
||||||
"foreground": "#FFE082",
|
"foreground": "#FFE082",
|
||||||
"properties": {
|
"properties": {
|
||||||
"user_info_separator": "",
|
|
||||||
"display_host": false,
|
|
||||||
"prefix": "@",
|
"prefix": "@",
|
||||||
"postfix": " \u279C"
|
"postfix": " \u279C",
|
||||||
|
"template": "{{ .UserName }}"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
|
@ -29,8 +29,7 @@
|
||||||
"background": "#003543",
|
"background": "#003543",
|
||||||
"properties": {
|
"properties": {
|
||||||
"prefix": "",
|
"prefix": "",
|
||||||
"display_host": false,
|
"template": "{{ .UserName }}"
|
||||||
"postfix": " "
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
|
@ -12,8 +12,7 @@
|
||||||
"leading_diamond": "",
|
"leading_diamond": "",
|
||||||
"trailing_diamond": "\uE0B0",
|
"trailing_diamond": "\uE0B0",
|
||||||
"properties": {
|
"properties": {
|
||||||
"postfix": " ",
|
"template": "{{ .UserName }}"
|
||||||
"display_host": false
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
|
@ -27,7 +27,10 @@
|
||||||
"foreground": "#ffffff",
|
"foreground": "#ffffff",
|
||||||
"background": "#4707a8",
|
"background": "#4707a8",
|
||||||
"leading_diamond": "\uE0B6",
|
"leading_diamond": "\uE0B6",
|
||||||
"trailing_diamond": "\uE0B0"
|
"trailing_diamond": "\uE0B0",
|
||||||
|
"properties": {
|
||||||
|
"template": "{{ .UserName }}@{{ .ComputerName }}"
|
||||||
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"type": "az",
|
"type": "az",
|
||||||
|
|
|
@ -178,8 +178,7 @@
|
||||||
"foreground": "#ffffff",
|
"foreground": "#ffffff",
|
||||||
"background": "#DC291E",
|
"background": "#DC291E",
|
||||||
"properties": {
|
"properties": {
|
||||||
"postfix": " ",
|
"template": "{{ .UserName }}"
|
||||||
"display_host": false
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
|
@ -20,8 +20,8 @@
|
||||||
"foreground": "#f1184c",
|
"foreground": "#f1184c",
|
||||||
"background": "#242424",
|
"background": "#242424",
|
||||||
"properties": {
|
"properties": {
|
||||||
"display_host": false,
|
"postfix": "",
|
||||||
"postfix": ""
|
"template": "{{ .UserName }}"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
|
@ -34,8 +34,7 @@
|
||||||
"properties": {
|
"properties": {
|
||||||
"prefix": "",
|
"prefix": "",
|
||||||
"display_host": true,
|
"display_host": true,
|
||||||
"host_color": "#e06c75",
|
"template": "{{ .UserName }}<#000000>@</><#e06c75>{{ .ComputerName }}</>"
|
||||||
"user_info_separator": "<#000000>@</>"
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
"trailing_diamond": "",
|
"trailing_diamond": "",
|
||||||
"properties": {
|
"properties": {
|
||||||
"prefix": "",
|
"prefix": "",
|
||||||
"display_host": false
|
"template": "{{ .UserName }}"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
|
@ -17,7 +17,10 @@
|
||||||
"style": "powerline",
|
"style": "powerline",
|
||||||
"powerline_symbol": "\uE0B0",
|
"powerline_symbol": "\uE0B0",
|
||||||
"foreground": "#100e23",
|
"foreground": "#100e23",
|
||||||
"background": "#ffffff"
|
"background": "#ffffff",
|
||||||
|
"properties": {
|
||||||
|
"template": "{{ .UserName }}@{{ .ComputerName }}"
|
||||||
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"type": "path",
|
"type": "path",
|
||||||
|
|
|
@ -82,12 +82,8 @@
|
||||||
"foreground": "#ffea00",
|
"foreground": "#ffea00",
|
||||||
"background": "#2f2f2f",
|
"background": "#2f2f2f",
|
||||||
"properties": {
|
"properties": {
|
||||||
"display_host": false,
|
"postfix": "<#ffea00> \ue0b1</>",
|
||||||
"user_info_separator": "<#ffea00 >\uf1fa</>",
|
"template": "{{ if ne .Env.POSH_SESSION_DEFAULT_USER .UserName }}{{ .UserName }}{{ end }}"
|
||||||
"display_default": false,
|
|
||||||
"user_color": "#ffea00",
|
|
||||||
"host_color": "#2EEFBF",
|
|
||||||
"postfix": "<#ffea00> \ue0b1</>"
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
|
@ -11,7 +11,10 @@
|
||||||
"foreground": "#ff0000",
|
"foreground": "#ff0000",
|
||||||
"background": "#333333",
|
"background": "#333333",
|
||||||
"leading_diamond": "\uE0B6",
|
"leading_diamond": "\uE0B6",
|
||||||
"trailing_diamond": "\uE0B0"
|
"trailing_diamond": "\uE0B0",
|
||||||
|
"properties": {
|
||||||
|
"template": "{{ .UserName }}@{{ .ComputerName }}"
|
||||||
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"type": "spotify",
|
"type": "spotify",
|
||||||
|
|
|
@ -64,7 +64,8 @@
|
||||||
"background": "#546E7A",
|
"background": "#546E7A",
|
||||||
"leading_diamond": "\uE0B2",
|
"leading_diamond": "\uE0B2",
|
||||||
"properties": {
|
"properties": {
|
||||||
"postfix": " <#26C6DA>\uE0B3</> "
|
"postfix": " <#26C6DA>\uE0B3</> ",
|
||||||
|
"template": "{{ .UserName }}@{{ .ComputerName }}"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
|
@ -13,7 +13,10 @@
|
||||||
{
|
{
|
||||||
"type": "session",
|
"type": "session",
|
||||||
"style": "plain",
|
"style": "plain",
|
||||||
"foreground": "#ffffff"
|
"foreground": "#ffffff",
|
||||||
|
"properties": {
|
||||||
|
"template": "{{ .UserName }}@{{ .ComputerName }}"
|
||||||
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"type": "path",
|
"type": "path",
|
||||||
|
|
|
@ -14,10 +14,8 @@
|
||||||
"style": "plain",
|
"style": "plain",
|
||||||
"foreground": "#BF616A",
|
"foreground": "#BF616A",
|
||||||
"properties": {
|
"properties": {
|
||||||
"display_host": false,
|
"prefix": "",
|
||||||
"display_user": true,
|
"template": "{{ .UserName }}"
|
||||||
"user_info_separator": "",
|
|
||||||
"prefix": ""
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
|
@ -14,7 +14,7 @@
|
||||||
"trailing_diamond": "",
|
"trailing_diamond": "",
|
||||||
"properties": {
|
"properties": {
|
||||||
"prefix": "",
|
"prefix": "",
|
||||||
"display_host": false
|
"template": "{{ .UserName }}"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
|
@ -29,9 +29,8 @@
|
||||||
"background": "#0A703E",
|
"background": "#0A703E",
|
||||||
"foreground": "#ffffff",
|
"foreground": "#ffffff",
|
||||||
"properties": {
|
"properties": {
|
||||||
"display_host": false,
|
|
||||||
"prefix": "",
|
"prefix": "",
|
||||||
"postfix": " "
|
"template": "{{ .UserName }}"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
|
@ -29,9 +29,9 @@
|
||||||
"background": "#E0E0E0",
|
"background": "#E0E0E0",
|
||||||
"foreground": "#424242",
|
"foreground": "#424242",
|
||||||
"properties": {
|
"properties": {
|
||||||
"display_host": false,
|
|
||||||
"prefix": "",
|
"prefix": "",
|
||||||
"postfix": ""
|
"postfix": "",
|
||||||
|
"template": "{{ .UserName }}"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
|
@ -1304,43 +1304,14 @@
|
||||||
"properties": {
|
"properties": {
|
||||||
"properties": {
|
"properties": {
|
||||||
"properties": {
|
"properties": {
|
||||||
"user_info_separator": {
|
|
||||||
"type": "string",
|
|
||||||
"title": "User Info Separator",
|
|
||||||
"description": "Text/icon to put in between the user and host name",
|
|
||||||
"default": "@"
|
|
||||||
},
|
|
||||||
"ssh_icon": {
|
"ssh_icon": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"title": "SSH Icon",
|
"title": "SSH Icon",
|
||||||
"description": "Text/icon to display first when in an active SSH session",
|
"description": "Text/icon to display first when in an active SSH session",
|
||||||
"default": "\uF817"
|
"default": "\uF817"
|
||||||
},
|
},
|
||||||
"user_color": { "$ref": "#/definitions/color" },
|
"template": {
|
||||||
"host_color": { "$ref": "#/definitions/color" },
|
"$ref": "#/definitions/template"
|
||||||
"display_user": {
|
|
||||||
"type": "boolean",
|
|
||||||
"title": "Display User",
|
|
||||||
"description": "Display the user name or not",
|
|
||||||
"default": true
|
|
||||||
},
|
|
||||||
"display_host": {
|
|
||||||
"type": "boolean",
|
|
||||||
"title": "Display Host",
|
|
||||||
"description": "Display the host name or not",
|
|
||||||
"default": true
|
|
||||||
},
|
|
||||||
"default_user_name": {
|
|
||||||
"type": "string",
|
|
||||||
"title": "Default User Name",
|
|
||||||
"description": "The name of the default user",
|
|
||||||
"default": ""
|
|
||||||
},
|
|
||||||
"display_default": {
|
|
||||||
"type": "boolean",
|
|
||||||
"title": "Display Default User",
|
|
||||||
"description": "Display the segment when default user or not",
|
|
||||||
"default": true
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,11 +42,8 @@
|
||||||
"foreground": "#fafafa",
|
"foreground": "#fafafa",
|
||||||
"background": "#2f2f2f",
|
"background": "#2f2f2f",
|
||||||
"properties": {
|
"properties": {
|
||||||
"user_info_separator": "<#7a7a7a>\uf1fa</>",
|
"postfix": "<#7a7a7a> \ue0b1</>",
|
||||||
"display_default": false,
|
"template": "{{ if ne .Env.POSH_SESSION_DEFAULT_USER .UserName }}<#77f5d6>{{ .UserName }}</><#7a7a7a>\uf1fa</><#2EEFBF>{{ end }}{{ .ComputerName }}</>"
|
||||||
"user_color": "#77f5d6",
|
|
||||||
"host_color": "#2EEFBF",
|
|
||||||
"postfix": "<#7a7a7a> \ue0b1</>"
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
|
@ -42,11 +42,8 @@
|
||||||
"foreground": "#fafafa",
|
"foreground": "#fafafa",
|
||||||
"background": "#2f2f2f",
|
"background": "#2f2f2f",
|
||||||
"properties": {
|
"properties": {
|
||||||
"user_info_separator": "<#7a7a7a>\uf1fa</>",
|
"postfix": "<#7a7a7a> \ue0b1</>",
|
||||||
"display_default": false,
|
"template": "{{ if ne .Env.POSH_SESSION_DEFAULT_USER .UserName }}<#77f5d6>{{ .UserName }}</><#7a7a7a>\uf1fa</><#2EEFBF>{{ .ComputerName }}{{ end }}</>"
|
||||||
"user_color": "#77f5d6",
|
|
||||||
"host_color": "#2EEFBF",
|
|
||||||
"postfix": "<#7a7a7a> \ue0b1</>"
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
|
@ -21,7 +21,11 @@
|
||||||
{
|
{
|
||||||
"type": "session",
|
"type": "session",
|
||||||
"style": "plain",
|
"style": "plain",
|
||||||
"foreground": "#FFFFFF"
|
"foreground": "#FFFFFF",
|
||||||
|
"properties": {
|
||||||
|
"prefix": "",
|
||||||
|
"template": "{{ .UserName }}@{{ .ComputerName }}"
|
||||||
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"type": "path",
|
"type": "path",
|
||||||
|
|
|
@ -25,11 +25,8 @@
|
||||||
"style": "plain",
|
"style": "plain",
|
||||||
"foreground": "#26C6DA",
|
"foreground": "#26C6DA",
|
||||||
"properties": {
|
"properties": {
|
||||||
"display_host": false,
|
|
||||||
"prefix": " ",
|
|
||||||
"postfix": ": ",
|
"postfix": ": ",
|
||||||
"user_info_separator": "",
|
"template": "{{ .UserName }}"
|
||||||
"display_user": true
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
|
@ -16,10 +16,8 @@
|
||||||
"invert_powerline": false,
|
"invert_powerline": false,
|
||||||
"foreground": "lightYellow",
|
"foreground": "lightYellow",
|
||||||
"properties": {
|
"properties": {
|
||||||
"display_host": false,
|
|
||||||
"prefix": "",
|
"prefix": "",
|
||||||
"user_info_separator": "",
|
"template": "{{ .UserName }}"
|
||||||
"display_user": true
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
|
@ -48,7 +48,7 @@
|
||||||
"foreground": "#757575",
|
"foreground": "#757575",
|
||||||
"properties": {
|
"properties": {
|
||||||
"prefix": "\u250c ",
|
"prefix": "\u250c ",
|
||||||
"display_host": true
|
"template": "{{ .UserName }}@{{ .ComputerName }}"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
|
@ -18,7 +18,8 @@
|
||||||
"type": "session",
|
"type": "session",
|
||||||
"style": "plain",
|
"style": "plain",
|
||||||
"properties": {
|
"properties": {
|
||||||
"prefix": ""
|
"prefix": "",
|
||||||
|
"template": "{{ .UserName }}@{{ .ComputerName }}"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
|
@ -43,10 +43,8 @@
|
||||||
"type": "session",
|
"type": "session",
|
||||||
"style": "plain",
|
"style": "plain",
|
||||||
"properties": {
|
"properties": {
|
||||||
"user_info_separator": " <darkGray>@</> ",
|
|
||||||
"prefix": "",
|
"prefix": "",
|
||||||
"user_color": "cyan",
|
"template": "<cyan>{{ .UserName }}</> <darkGray>@</> <green>{{ .ComputerName }}</>"
|
||||||
"host_color": "green"
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
|
@ -10,9 +10,8 @@
|
||||||
"style": "plain",
|
"style": "plain",
|
||||||
"foreground": "#E36464",
|
"foreground": "#E36464",
|
||||||
"properties": {
|
"properties": {
|
||||||
"user_info_separator": "",
|
"prefix": "@",
|
||||||
"display_host": false,
|
"template": "{{ .UserName }}"
|
||||||
"prefix": "@"
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue