mirror of
https://github.com/JanDeDobbeleer/oh-my-posh.git
synced 2025-01-13 12:17:26 -08:00
parent
09255ae63d
commit
5b275cc155
|
@ -30,5 +30,8 @@ to `\uF817 `
|
|||
- 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_user: `boolean` - display the segment or not when the user matches `default_user_name` - defaults
|
||||
to `true`
|
||||
|
||||
[colors]: /docs/configure#colors
|
||||
|
|
|
@ -6,8 +6,9 @@ import (
|
|||
)
|
||||
|
||||
type session struct {
|
||||
props *properties
|
||||
env environmentInfo
|
||||
props *properties
|
||||
env environmentInfo
|
||||
userName string
|
||||
}
|
||||
|
||||
const (
|
||||
|
@ -23,9 +24,19 @@ const (
|
|||
DisplayUser Property = "display_user"
|
||||
// SSHIcon shows when in an SSH session
|
||||
SSHIcon Property = "ssh_icon"
|
||||
// DefaultUserName holds the default user of the platform
|
||||
DefaultUserName Property = "default_user_name"
|
||||
// DisplayDefaultUser hides or shows the user name when it's the user set in DefaultUserName
|
||||
DisplayDefaultUser Property = "display_default_user"
|
||||
)
|
||||
|
||||
func (s *session) enabled() bool {
|
||||
s.userName = s.getUserName()
|
||||
showDefaultUser := s.props.getBool(DisplayDefaultUser, true)
|
||||
defaultUser := s.props.getString(DefaultUserName, "")
|
||||
if !showDefaultUser && defaultUser == s.userName {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
|
@ -39,7 +50,7 @@ func (s *session) init(props *properties, env environmentInfo) {
|
|||
}
|
||||
|
||||
func (s *session) getFormattedText() string {
|
||||
username := s.getUserName()
|
||||
username := s.userName
|
||||
computername := s.getComputerName()
|
||||
separator := ""
|
||||
if s.props.getBool(DisplayHost, true) && s.props.getBool(DisplayUser, true) {
|
||||
|
|
|
@ -40,6 +40,7 @@ func setupSession(args *sessionArgs) session {
|
|||
|
||||
func testUserInfoWriter(args *sessionArgs) string {
|
||||
s := setupSession(args)
|
||||
_ = s.enabled()
|
||||
return s.getFormattedText()
|
||||
}
|
||||
|
||||
|
@ -77,6 +78,7 @@ func TestWriteOnlyUsername(t *testing.T) {
|
|||
s := setupSession(args)
|
||||
s.props.values[DisplayHost] = false
|
||||
want := "<#fff>bill</><#fff></>"
|
||||
assert.True(t, s.enabled())
|
||||
got := s.getFormattedText()
|
||||
assert.EqualValues(t, want, got)
|
||||
}
|
||||
|
@ -91,6 +93,7 @@ func TestWriteOnlyHostname(t *testing.T) {
|
|||
s := setupSession(args)
|
||||
s.props.values[DisplayUser] = false
|
||||
want := "<#fff></><#fff>surface</>"
|
||||
assert.True(t, s.enabled())
|
||||
got := s.getFormattedText()
|
||||
assert.EqualValues(t, want, got)
|
||||
}
|
||||
|
|
|
@ -952,6 +952,18 @@
|
|||
"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_user": {
|
||||
"type": "boolean",
|
||||
"title": "Display Default User",
|
||||
"description": "Display the segment when default user or not",
|
||||
"default": true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue