diff --git a/docs/docs/config-example.md b/docs/docs/config-example.md index c180c4f4..51adc468 100644 --- a/docs/docs/config-example.md +++ b/docs/docs/config-example.md @@ -36,7 +36,7 @@ sidebar_label: Sample "leading_diamond": "\uE0B6", "trailing_diamond": "\uE0B0", "properties": { - "postfix": " " + "template": "{{ .UserName }}" } }, { diff --git a/docs/docs/segment-session.md b/docs/docs/segment-session.md index 411e40ce..53ffee6c 100644 --- a/docs/docs/segment-session.md +++ b/docs/docs/segment-session.md @@ -17,37 +17,26 @@ Show the current user and host name. "foreground": "#ffffff", "background": "#c386f1", "leading_diamond": "\uE0B6", - "trailing_diamond": "\uE0B0" + "trailing_diamond": "\uE0B0", + "properties": { + "template": "{{ .UserName }}" + } } ``` ## 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 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 -properties below. Only used when a value is set, making the above properties obsolete. +properties below. ## Template Properties - `.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 - `.SSHSession`: `boolean` - active SSH session 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/ [sprig]: https://masterminds.github.io/sprig/ diff --git a/src/segment_deprecated.go b/src/segment_deprecated.go index 334fdd08..8dd728aa 100644 --- a/src/segment_deprecated.go +++ b/src/segment_deprecated.go @@ -238,3 +238,69 @@ func (b *batt) shouldDisplay() bool { } 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) +} diff --git a/src/segment_deprecated_test.go b/src/segment_deprecated_test.go index 7363c48e..367e5e33 100644 --- a/src/segment_deprecated_test.go +++ b/src/segment_deprecated_test.go @@ -401,3 +401,198 @@ func TestBatterySegmentSingle(t *testing.T) { 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 company-laptop", + Host: "company-laptop", + DisplayUser: true, + DisplayHost: true, + UserName: "john", + HostColor: "yellow", + ExpectedEnabled: true, + }, + { + Case: "user and computer with user color", + ExpectedString: "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: "john at 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) + } + } +} diff --git a/src/segment_session.go b/src/segment_session.go index 40ccb168..4bfe754a 100644 --- a/src/segment_session.go +++ b/src/segment_session.go @@ -1,68 +1,51 @@ package main -import ( - "fmt" - "strings" -) +import "strings" type session struct { - props properties - env environmentInfo - UserName string + props properties + env environmentInfo + text string + + UserName string + ComputerName string + SSHSession bool + Root bool + DefaultUserName string - ComputerName string - SSHSession bool - Root bool - templateText string } 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" - // SSHIcon shows when in an SSH session + // SSHIcon is the icon used for SSH sessions 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 { + s.SSHSession = s.activeSSHSession() + segmentTemplate := s.props.getString(SegmentTemplate, "") + if segmentTemplate == "" { + return s.legacyEnabled() + } s.UserName = s.getUserName() s.ComputerName = s.getComputerName() - s.SSHSession = s.activeSSHSession() - s.DefaultUserName = s.getDefaultUser() - segmentTemplate := s.props.getString(SegmentTemplate, "") - if segmentTemplate != "" { - s.Root = s.env.isRunningAsRoot() - 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 + s.Root = s.env.isRunningAsRoot() + template := &textTemplate{ + Template: segmentTemplate, + Context: s, + Env: s.env, } - showDefaultUser := s.props.getBool(DisplayDefault, true) - if !showDefaultUser && s.DefaultUserName == s.UserName { - return false + var err error + s.text, err = template.render() + if err != nil { + s.text = err.Error() } - return true + return len(s.text) > 0 } func (s *session) string() string { + if len(s.text) != 0 { + return s.text + } return s.getFormattedText() } @@ -71,48 +54,7 @@ func (s *session) init(props properties, env environmentInfo) { 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 { - if !s.props.getBool(DisplayUser, true) { - return "" - } user := s.env.getCurrentUser() username := strings.TrimSpace(user) if s.env.getRuntimeGOOS() == "windows" && strings.Contains(username, "\\") { @@ -121,12 +63,12 @@ func (s *session) getUserName() string { return username } -func (s *session) getDefaultUser() string { - user := s.env.getenv(defaultUserEnvVar) - if len(user) == 0 { - user = s.props.getString(DefaultUserName, "") +func (s *session) getComputerName() string { + computername, err := s.env.getHostName() + if err != nil { + computername = "unknown" } - return user + return strings.TrimSpace(computername) } func (s *session) activeSSHSession() bool { diff --git a/src/segment_session_test.go b/src/segment_session_test.go index d7fa05c3..973c0770 100644 --- a/src/segment_session_test.go +++ b/src/segment_session_test.go @@ -1,205 +1,11 @@ package main import ( - "errors" "testing" "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 company-laptop", - Host: "company-laptop", - DisplayUser: true, - DisplayHost: true, - UserName: "john", - HostColor: "yellow", - ExpectedEnabled: true, - }, - { - Case: "user and computer with user color", - ExpectedString: "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: "john at 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) { cases := []struct { Case string @@ -217,14 +23,14 @@ func TestSessionSegmentTemplate(t *testing.T) { ExpectedString: "john@company-laptop", ComputerName: "company-laptop", UserName: "john", - Template: "{{.UserName}}{{if .ComputerName}}@{{.ComputerName}}{{end}}", + Template: "{{.UserName}}@{{.ComputerName}}", ExpectedEnabled: true, }, { Case: "user only", ExpectedString: "john", UserName: "john", - Template: "{{.UserName}}{{if .ComputerName}}@{{.ComputerName}}{{end}}", + Template: "{{.UserName}}", ExpectedEnabled: true, }, { @@ -272,7 +78,7 @@ func TestSessionSegmentTemplate(t *testing.T) { SSHSession: true, ComputerName: "remote", Root: true, - Template: "{{if ne .DefaultUserName .UserName}}{{.UserName}}{{end}}", + Template: "{{if ne .Env.POSH_SESSION_DEFAULT_USER .UserName}}{{.UserName}}{{end}}", ExpectedEnabled: true, }, { @@ -283,7 +89,7 @@ func TestSessionSegmentTemplate(t *testing.T) { SSHSession: true, ComputerName: "remote", Root: true, - Template: "{{if ne .DefaultUserName .UserName}}{{.UserName}}{{end}}", + Template: "{{if ne .Env.POSH_SESSION_DEFAULT_USER .UserName}}{{.UserName}}{{end}}", ExpectedEnabled: false, }, } diff --git a/src/test/jandedobbeleer-palette.omp.json b/src/test/jandedobbeleer-palette.omp.json index 61252309..d14ca722 100644 --- a/src/test/jandedobbeleer-palette.omp.json +++ b/src/test/jandedobbeleer-palette.omp.json @@ -43,8 +43,7 @@ "leading_diamond": "", "trailing_diamond": "\uE0B0", "properties": { - "postfix": " ", - "display_host": false + "template": "{{ .UserName }}" } }, { diff --git a/src/test/jandedobbeleer.omp.json b/src/test/jandedobbeleer.omp.json index faf2700b..c6719220 100644 --- a/src/test/jandedobbeleer.omp.json +++ b/src/test/jandedobbeleer.omp.json @@ -12,8 +12,7 @@ "leading_diamond": "", "trailing_diamond": "\uE0B0", "properties": { - "postfix": " ", - "display_host": false + "template": "{{ .UserName }}" } }, { diff --git a/themes/M365Princess.omp.json b/themes/M365Princess.omp.json index 8138284c..7262353c 100644 --- a/themes/M365Princess.omp.json +++ b/themes/M365Princess.omp.json @@ -15,7 +15,7 @@ "trailing_diamond": "", "properties": { "prefix": "", - "display_host": false + "template": "{{ .UserName }}" } }, { diff --git a/themes/agnoster.omp.json b/themes/agnoster.omp.json index 844e1666..2740d32c 100644 --- a/themes/agnoster.omp.json +++ b/themes/agnoster.omp.json @@ -17,7 +17,10 @@ "style": "powerline", "powerline_symbol": "\uE0B0", "foreground": "#100e23", - "background": "#ffffff" + "background": "#ffffff", + "properties": { + "template": "{{ .UserName }}@{{ .ComputerName }}" + } }, { "type": "path", diff --git a/themes/agnosterplus.omp.json b/themes/agnosterplus.omp.json index 3833e92e..08516f05 100644 --- a/themes/agnosterplus.omp.json +++ b/themes/agnosterplus.omp.json @@ -26,7 +26,10 @@ "style": "powerline", "powerline_symbol": "\uE0B0", "foreground": "#100e23", - "background": "#ffffff" + "background": "#ffffff", + "properties": { + "template": "{{ .UserName }}@{{ .ComputerName }}" + } }, { "type": "path", diff --git a/themes/aliens.omp.json b/themes/aliens.omp.json index da2ab2a5..aeb45557 100644 --- a/themes/aliens.omp.json +++ b/themes/aliens.omp.json @@ -11,7 +11,10 @@ "foreground": "#ffffff", "background": "#61AFEF", "leading_diamond": "\uE0B6", - "trailing_diamond": "\uE0B0" + "trailing_diamond": "\uE0B0", + "properties": { + "template": "{{ .UserName }}@{{ .ComputerName }}" + } }, { "type": "path", diff --git a/themes/amro.omp.json b/themes/amro.omp.json index 7ea759e2..0d5c1cb5 100644 --- a/themes/amro.omp.json +++ b/themes/amro.omp.json @@ -10,9 +10,9 @@ "style": "plain", "foreground": "#45F1C2", "properties": { - "display_host": false, "prefix": "\uf508 ", - "postfix": " on" + "postfix": " on", + "template": "{{ .UserName }}" } }, { diff --git a/themes/atomicBit.omp.json b/themes/atomicBit.omp.json index dbf3c782..cba7f86b 100644 --- a/themes/atomicBit.omp.json +++ b/themes/atomicBit.omp.json @@ -11,11 +11,9 @@ "type": "session", "style": "plain", "properties": { - "user_info_separator": "<#ff5555>@", "prefix": "╭─[", "postfix": "]─", - "user_color": "#ffff55", - "host_color": "#55ff55" + "template": "<#ffff55>{{ .UserName }}<#ff5555>@<#55ff55>{{ .ComputerName }}" } }, { diff --git a/themes/blue-owl.omp.json b/themes/blue-owl.omp.json index eb5ff5e2..80a5d0cc 100644 --- a/themes/blue-owl.omp.json +++ b/themes/blue-owl.omp.json @@ -101,7 +101,7 @@ "properties": { "postfix": "", "prefix": " ", - "user_info_separator": " / " + "template": "{{ .UserName }} / {{ .ComputerName }}" } }, { diff --git a/themes/blueish.omp.json b/themes/blueish.omp.json index ebff24ae..5293532b 100644 --- a/themes/blueish.omp.json +++ b/themes/blueish.omp.json @@ -22,7 +22,10 @@ "style": "powerline", "foreground": "#26C6DA", "background": "#546E7A", - "powerline_symbol": "\uE0B0" + "powerline_symbol": "\uE0B0", + "properties": { + "template": "{{ .UserName }}@{{ .ComputerName }}" + } }, { "type": "battery", diff --git a/themes/bubbles.omp.json b/themes/bubbles.omp.json index a4909205..f6dc58a4 100644 --- a/themes/bubbles.omp.json +++ b/themes/bubbles.omp.json @@ -14,9 +14,9 @@ "foreground": "#E64747", "background": "#29315A", "properties": { - "display_host": false, "postfix": "", - "prefix": "" + "prefix": "", + "template": "{{ .UserName }}" } }, { diff --git a/themes/bubblesline.omp.json b/themes/bubblesline.omp.json index e9c74236..e1f54b10 100644 --- a/themes/bubblesline.omp.json +++ b/themes/bubblesline.omp.json @@ -144,9 +144,9 @@ "foreground": "#9B6BDF", "background": "#424242", "properties": { - "display_host": false, "postfix": " \u276F", - "prefix": "" + "prefix": "", + "template": "{{ .UserName }}" } } ] diff --git a/themes/cert.omp.json b/themes/cert.omp.json index effd1d75..72abe209 100644 --- a/themes/cert.omp.json +++ b/themes/cert.omp.json @@ -13,10 +13,9 @@ "background": "#E36464", "foreground": "#fff", "properties": { - "user_info_separator": "", - "display_host": false, "prefix": "", - "postfix": " " + "postfix": " ", + "template": "{{ .UserName }}" } }, { diff --git a/themes/cinnamon.omp.json b/themes/cinnamon.omp.json index 0deef5c0..af641368 100644 --- a/themes/cinnamon.omp.json +++ b/themes/cinnamon.omp.json @@ -10,7 +10,10 @@ "style": "diamond", "foreground": "#ffffff", "background": "#07585c", - "leading_diamond": "\uE0B6" + "leading_diamond": "\uE0B6", + "properties": { + "template": "{{ .UserName }}@{{ .ComputerName }}" + } }, { "type": "path", diff --git a/themes/darkblood.omp.json b/themes/darkblood.omp.json index 3ea567b8..6bfb0bd9 100644 --- a/themes/darkblood.omp.json +++ b/themes/darkblood.omp.json @@ -10,10 +10,9 @@ "style": "plain", "foreground": "#ffffff", "properties": { - "user_info_separator": "", - "display_host": false, "prefix": "<#CB4B16>┏[", - "postfix": "<#CB4B16>]" + "postfix": "<#CB4B16>]", + "template": "{{ .UserName }}" } }, { diff --git a/themes/festivetech.omp.json b/themes/festivetech.omp.json index d58993f2..b35b3727 100644 --- a/themes/festivetech.omp.json +++ b/themes/festivetech.omp.json @@ -15,7 +15,7 @@ "trailing_diamond": "", "properties": { "prefix": "", - "display_host": false + "template": "{{ .UserName }}" } }, { diff --git a/themes/fish.omp.json b/themes/fish.omp.json index 21d979dd..4594e5e1 100644 --- a/themes/fish.omp.json +++ b/themes/fish.omp.json @@ -22,7 +22,10 @@ { "type": "session", "style": "plain", - "foreground": "#ffffff" + "foreground": "#ffffff", + "properties": { + "template": "{{ .UserName }}@{{ .ComputerName }}" + } }, { "type": "path", diff --git a/themes/gmay.omp.json b/themes/gmay.omp.json index 331c0aa0..fa43804a 100644 --- a/themes/gmay.omp.json +++ b/themes/gmay.omp.json @@ -16,7 +16,10 @@ "type": "session", "style": "powerline", "foreground": "#ffffff", - "background": "#3A86FF" + "background": "#3A86FF", + "properties": { + "template": "{{ .UserName }}@{{ .ComputerName }}" + } }, { "type": "path", diff --git a/themes/half-life.omp.json b/themes/half-life.omp.json index af46a6d0..f06d0d7a 100644 --- a/themes/half-life.omp.json +++ b/themes/half-life.omp.json @@ -10,8 +10,8 @@ "style": "plain", "foreground": "#7E46B6", "properties": { - "display_host": false, - "prefix": "" + "prefix": "", + "template": "{{ .UserName }}" } }, { diff --git a/themes/honukai.omp.json b/themes/honukai.omp.json index b7250344..d4e5d773 100644 --- a/themes/honukai.omp.json +++ b/themes/honukai.omp.json @@ -10,10 +10,8 @@ "style": "plain", "foreground": "#FFFFFF", "properties": { - "user_info_separator": " <#ffffff>in ", "prefix": "<#0377C8># ", - "user_color": "#0377C8", - "host_color": "#4A9207" + "template": "<#0377C8>{{ .UserName }} <#ffffff>in <#4A9207>{{ .ComputerName }}" } }, { diff --git a/themes/hunk.omp.json b/themes/hunk.omp.json index 3f04318f..618adaa2 100644 --- a/themes/hunk.omp.json +++ b/themes/hunk.omp.json @@ -109,9 +109,7 @@ "foreground": "#ffffff", "background": "#86BBD8", "properties": { - "prefix": " ", - "postfix": " ", - "display_host": false + "template": "{{ .UserName }}" } }, { diff --git a/themes/huvix.omp.json b/themes/huvix.omp.json index 607fb7cd..c913a20f 100644 --- a/themes/huvix.omp.json +++ b/themes/huvix.omp.json @@ -10,10 +10,9 @@ "style": "plain", "foreground": "#FFE082", "properties": { - "user_info_separator": "", - "display_host": false, "prefix": "@", - "postfix": " \u279C" + "postfix": " \u279C", + "template": "{{ .UserName }}" } }, { diff --git a/themes/iterm2.omp.json b/themes/iterm2.omp.json index 3124efad..09d675c4 100644 --- a/themes/iterm2.omp.json +++ b/themes/iterm2.omp.json @@ -29,8 +29,7 @@ "background": "#003543", "properties": { "prefix": "", - "display_host": false, - "postfix": " " + "template": "{{ .UserName }}" } }, { diff --git a/themes/jandedobbeleer.omp.json b/themes/jandedobbeleer.omp.json index faf2700b..c6719220 100644 --- a/themes/jandedobbeleer.omp.json +++ b/themes/jandedobbeleer.omp.json @@ -12,8 +12,7 @@ "leading_diamond": "", "trailing_diamond": "\uE0B0", "properties": { - "postfix": " ", - "display_host": false + "template": "{{ .UserName }}" } }, { diff --git a/themes/jonnychipz.omp.json b/themes/jonnychipz.omp.json index 15c659bd..7f4c3732 100644 --- a/themes/jonnychipz.omp.json +++ b/themes/jonnychipz.omp.json @@ -27,7 +27,10 @@ "foreground": "#ffffff", "background": "#4707a8", "leading_diamond": "\uE0B6", - "trailing_diamond": "\uE0B0" + "trailing_diamond": "\uE0B0", + "properties": { + "template": "{{ .UserName }}@{{ .ComputerName }}" + } }, { "type": "az", diff --git a/themes/jv_sitecorian.omp.json b/themes/jv_sitecorian.omp.json index 31228766..dafdafa9 100644 --- a/themes/jv_sitecorian.omp.json +++ b/themes/jv_sitecorian.omp.json @@ -178,8 +178,7 @@ "foreground": "#ffffff", "background": "#DC291E", "properties": { - "postfix": " ", - "display_host": false + "template": "{{ .UserName }}" } } ] diff --git a/themes/microverse-power.omp.json b/themes/microverse-power.omp.json index c9bdad78..35013e54 100644 --- a/themes/microverse-power.omp.json +++ b/themes/microverse-power.omp.json @@ -20,8 +20,8 @@ "foreground": "#f1184c", "background": "#242424", "properties": { - "display_host": false, - "postfix": "" + "postfix": "", + "template": "{{ .UserName }}" } }, { diff --git a/themes/mojada.omp.json b/themes/mojada.omp.json index a903bde1..8c9e56cb 100644 --- a/themes/mojada.omp.json +++ b/themes/mojada.omp.json @@ -34,8 +34,7 @@ "properties": { "prefix": "", "display_host": true, - "host_color": "#e06c75", - "user_info_separator": "<#000000>@" + "template": "{{ .UserName }}<#000000>@<#e06c75>{{ .ComputerName }}" } }, { diff --git a/themes/mt.omp.json b/themes/mt.omp.json index 08cbae2c..abab8990 100644 --- a/themes/mt.omp.json +++ b/themes/mt.omp.json @@ -15,7 +15,7 @@ "trailing_diamond": "", "properties": { "prefix": "", - "display_host": false + "template": "{{ .UserName }}" } }, { diff --git a/themes/paradox.omp.json b/themes/paradox.omp.json index 5616d7bb..40d458cc 100644 --- a/themes/paradox.omp.json +++ b/themes/paradox.omp.json @@ -17,7 +17,10 @@ "style": "powerline", "powerline_symbol": "\uE0B0", "foreground": "#100e23", - "background": "#ffffff" + "background": "#ffffff", + "properties": { + "template": "{{ .UserName }}@{{ .ComputerName }}" + } }, { "type": "path", diff --git a/themes/pixelrobots.omp.json b/themes/pixelrobots.omp.json index dfa874a0..0e79ba92 100644 --- a/themes/pixelrobots.omp.json +++ b/themes/pixelrobots.omp.json @@ -82,12 +82,8 @@ "foreground": "#ffea00", "background": "#2f2f2f", "properties": { - "display_host": false, - "user_info_separator": "<#ffea00 >\uf1fa", - "display_default": false, - "user_color": "#ffea00", - "host_color": "#2EEFBF", - "postfix": "<#ffea00> \ue0b1" + "postfix": "<#ffea00> \ue0b1", + "template": "{{ if ne .Env.POSH_SESSION_DEFAULT_USER .UserName }}{{ .UserName }}{{ end }}" } }, { diff --git a/themes/plague.omp.json b/themes/plague.omp.json index ecc7d6f9..a7e33b2f 100644 --- a/themes/plague.omp.json +++ b/themes/plague.omp.json @@ -11,7 +11,10 @@ "foreground": "#ff0000", "background": "#333333", "leading_diamond": "\uE0B6", - "trailing_diamond": "\uE0B0" + "trailing_diamond": "\uE0B0", + "properties": { + "template": "{{ .UserName }}@{{ .ComputerName }}" + } }, { "type": "spotify", diff --git a/themes/powerlevel10k_classic.omp.json b/themes/powerlevel10k_classic.omp.json index 3d12375b..d3f90172 100644 --- a/themes/powerlevel10k_classic.omp.json +++ b/themes/powerlevel10k_classic.omp.json @@ -64,7 +64,8 @@ "background": "#546E7A", "leading_diamond": "\uE0B2", "properties": { - "postfix": " <#26C6DA>\uE0B3 " + "postfix": " <#26C6DA>\uE0B3 ", + "template": "{{ .UserName }}@{{ .ComputerName }}" } }, { diff --git a/themes/powerline.omp.json b/themes/powerline.omp.json index a63d3c78..324b6c25 100644 --- a/themes/powerline.omp.json +++ b/themes/powerline.omp.json @@ -13,7 +13,10 @@ { "type": "session", "style": "plain", - "foreground": "#ffffff" + "foreground": "#ffffff", + "properties": { + "template": "{{ .UserName }}@{{ .ComputerName }}" + } }, { "type": "path", diff --git a/themes/pure.omp.json b/themes/pure.omp.json index 17a0dc98..2b4d2873 100644 --- a/themes/pure.omp.json +++ b/themes/pure.omp.json @@ -14,10 +14,8 @@ "style": "plain", "foreground": "#BF616A", "properties": { - "display_host": false, - "display_user": true, - "user_info_separator": "", - "prefix": "" + "prefix": "", + "template": "{{ .UserName }}" } }, { diff --git a/themes/remk.omp.json b/themes/remk.omp.json index 6e9d77cf..c738f19e 100644 --- a/themes/remk.omp.json +++ b/themes/remk.omp.json @@ -14,7 +14,7 @@ "trailing_diamond": "", "properties": { "prefix": "", - "display_host": false + "template": "{{ .UserName }}" } }, { diff --git a/themes/rudolfs-dark.omp.json b/themes/rudolfs-dark.omp.json index 5c382a16..873a559b 100644 --- a/themes/rudolfs-dark.omp.json +++ b/themes/rudolfs-dark.omp.json @@ -29,9 +29,8 @@ "background": "#0A703E", "foreground": "#ffffff", "properties": { - "display_host": false, "prefix": "", - "postfix": " " + "template": "{{ .UserName }}" } }, { diff --git a/themes/rudolfs-light.omp.json b/themes/rudolfs-light.omp.json index 61715576..1ee46d93 100644 --- a/themes/rudolfs-light.omp.json +++ b/themes/rudolfs-light.omp.json @@ -29,9 +29,9 @@ "background": "#E0E0E0", "foreground": "#424242", "properties": { - "display_host": false, "prefix": "", - "postfix": "" + "postfix": "", + "template": "{{ .UserName }}" } }, { diff --git a/themes/schema.json b/themes/schema.json index d93f5c7c..9e114529 100644 --- a/themes/schema.json +++ b/themes/schema.json @@ -1304,43 +1304,14 @@ "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": { "type": "string", "title": "SSH Icon", "description": "Text/icon to display first when in an active SSH session", "default": "\uF817" }, - "user_color": { "$ref": "#/definitions/color" }, - "host_color": { "$ref": "#/definitions/color" }, - "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 + "template": { + "$ref": "#/definitions/template" } } } diff --git a/themes/slim.omp.json b/themes/slim.omp.json index 620855db..655d7c3c 100644 --- a/themes/slim.omp.json +++ b/themes/slim.omp.json @@ -42,11 +42,8 @@ "foreground": "#fafafa", "background": "#2f2f2f", "properties": { - "user_info_separator": "<#7a7a7a>\uf1fa", - "display_default": false, - "user_color": "#77f5d6", - "host_color": "#2EEFBF", - "postfix": "<#7a7a7a> \ue0b1" + "postfix": "<#7a7a7a> \ue0b1", + "template": "{{ if ne .Env.POSH_SESSION_DEFAULT_USER .UserName }}<#77f5d6>{{ .UserName }}<#7a7a7a>\uf1fa<#2EEFBF>{{ end }}{{ .ComputerName }}" } }, { diff --git a/themes/slimfat.omp.json b/themes/slimfat.omp.json index 07f1c2eb..8a268c57 100644 --- a/themes/slimfat.omp.json +++ b/themes/slimfat.omp.json @@ -42,11 +42,8 @@ "foreground": "#fafafa", "background": "#2f2f2f", "properties": { - "user_info_separator": "<#7a7a7a>\uf1fa", - "display_default": false, - "user_color": "#77f5d6", - "host_color": "#2EEFBF", - "postfix": "<#7a7a7a> \ue0b1" + "postfix": "<#7a7a7a> \ue0b1", + "template": "{{ if ne .Env.POSH_SESSION_DEFAULT_USER .UserName }}<#77f5d6>{{ .UserName }}<#7a7a7a>\uf1fa<#2EEFBF>{{ .ComputerName }}{{ end }}" } }, { diff --git a/themes/sorin.omp.json b/themes/sorin.omp.json index 79fd63fb..1b6426aa 100644 --- a/themes/sorin.omp.json +++ b/themes/sorin.omp.json @@ -21,7 +21,11 @@ { "type": "session", "style": "plain", - "foreground": "#FFFFFF" + "foreground": "#FFFFFF", + "properties": { + "prefix": "", + "template": "{{ .UserName }}@{{ .ComputerName }}" + } }, { "type": "path", diff --git a/themes/space.omp.json b/themes/space.omp.json index 47d975bd..b6cd8a83 100644 --- a/themes/space.omp.json +++ b/themes/space.omp.json @@ -25,11 +25,8 @@ "style": "plain", "foreground": "#26C6DA", "properties": { - "display_host": false, - "prefix": " ", "postfix": ": ", - "user_info_separator": "", - "display_user": true + "template": "{{ .UserName }}" } }, { diff --git a/themes/spaceship.omp.json b/themes/spaceship.omp.json index 03ec6730..ec6c7315 100644 --- a/themes/spaceship.omp.json +++ b/themes/spaceship.omp.json @@ -16,10 +16,8 @@ "invert_powerline": false, "foreground": "lightYellow", "properties": { - "display_host": false, "prefix": "", - "user_info_separator": "", - "display_user": true + "template": "{{ .UserName }}" } }, { diff --git a/themes/stelbent.minimal.omp.json b/themes/stelbent.minimal.omp.json index 5b7e22bf..ac1c83ea 100644 --- a/themes/stelbent.minimal.omp.json +++ b/themes/stelbent.minimal.omp.json @@ -48,7 +48,7 @@ "foreground": "#757575", "properties": { "prefix": "\u250c ", - "display_host": true + "template": "{{ .UserName }}@{{ .ComputerName }}" } }, { diff --git a/themes/xtoys.omp.json b/themes/xtoys.omp.json index 451655f2..65b2d52b 100644 --- a/themes/xtoys.omp.json +++ b/themes/xtoys.omp.json @@ -18,7 +18,8 @@ "type": "session", "style": "plain", "properties": { - "prefix": "" + "prefix": "", + "template": "{{ .UserName }}@{{ .ComputerName }}" } }, { diff --git a/themes/ys.omp.json b/themes/ys.omp.json index 2fa1589e..fdb7611f 100644 --- a/themes/ys.omp.json +++ b/themes/ys.omp.json @@ -43,10 +43,8 @@ "type": "session", "style": "plain", "properties": { - "user_info_separator": " @ ", "prefix": "", - "user_color": "cyan", - "host_color": "green" + "template": "{{ .UserName }} @ {{ .ComputerName }}" } }, { diff --git a/themes/zash.omp.json b/themes/zash.omp.json index da80cd24..9124b787 100644 --- a/themes/zash.omp.json +++ b/themes/zash.omp.json @@ -10,9 +10,8 @@ "style": "plain", "foreground": "#E36464", "properties": { - "user_info_separator": "", - "display_host": false, - "prefix": "@" + "prefix": "@", + "template": "{{ .UserName }}" } }, {