mirror of
https://github.com/JanDeDobbeleer/oh-my-posh.git
synced 2025-01-13 12:17:26 -08:00
parent
59b0595c5b
commit
734158a8a3
|
@ -28,6 +28,8 @@ Display the currently active AWS profile and region.
|
|||
|
||||
- template: `string` - A go [text/template][go-text-template] template extended with [sprig][sprig] utilizing the
|
||||
properties below. Defaults to `{{.Context}}{{if .Namespace}} :: {{.Namespace}}{{end}}`
|
||||
- display_default: `boolean` - display the segment or not when the user profile matches `default` - defaults
|
||||
to `true`
|
||||
|
||||
## Template Properties
|
||||
|
||||
|
|
|
@ -27,7 +27,7 @@ Supports conda, virtualenv and pyenv.
|
|||
## Properties
|
||||
|
||||
- display_virtual_env: `boolean` - show the name of the virtualenv or not - defaults to `true`
|
||||
- display_default_env: `boolean` - show the name of the virtualenv when it's default (`system`, `base`)
|
||||
- display_default: `boolean` - show the name of the virtualenv when it's default (`system`, `base`)
|
||||
or not - defaults to `true`
|
||||
- display_version: `boolean` - display the python version - defaults to `true`
|
||||
- display_error: `boolean` - show the error context when failing to retrieve the version information - defaults to `true`
|
||||
|
|
|
@ -31,7 +31,7 @@ to `\uF817 `
|
|||
- 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
|
||||
- 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.
|
||||
|
|
|
@ -27,6 +27,8 @@ const (
|
|||
SegmentTemplate Property = "template"
|
||||
// DisplayError to display when an error occurs or not
|
||||
DisplayError Property = "display_error"
|
||||
// DisplayDefault hides or shows the default
|
||||
DisplayDefault Property = "display_default"
|
||||
)
|
||||
|
||||
type properties struct {
|
||||
|
|
|
@ -31,7 +31,11 @@ func (a *aws) enabled() bool {
|
|||
}
|
||||
return ""
|
||||
}
|
||||
displayDefaultUser := a.props.getBool(DisplayDefault, true)
|
||||
a.Profile = getEnvFirstMatch("AWS_VAULT", "AWS_PROFILE")
|
||||
if !displayDefaultUser && a.Profile == defaultUser {
|
||||
return false
|
||||
}
|
||||
a.Region = getEnvFirstMatch("AWS_DEFAULT_REGION", "AWS_REGION")
|
||||
if a.Profile != "" && a.Region != "" {
|
||||
return true
|
||||
|
@ -41,6 +45,9 @@ func (a *aws) enabled() bool {
|
|||
return true
|
||||
}
|
||||
a.getConfigFileInfo()
|
||||
if !displayDefaultUser && a.Profile == defaultUser {
|
||||
return false
|
||||
}
|
||||
return a.Profile != ""
|
||||
}
|
||||
|
||||
|
|
|
@ -17,8 +17,11 @@ func TestAWSSegment(t *testing.T) {
|
|||
DefaultRegion string
|
||||
ConfigFile string
|
||||
Template string
|
||||
DisplayDefault bool
|
||||
}{
|
||||
{Case: "disabled", ExpectedString: "", ExpectedEnabled: false},
|
||||
{Case: "enabled with default user", ExpectedString: "default@eu-west", Profile: "default", Region: "eu-west", ExpectedEnabled: true, DisplayDefault: true},
|
||||
{Case: "disabled with default user", ExpectedString: "default", Profile: "default", Region: "eu-west", ExpectedEnabled: false, DisplayDefault: false},
|
||||
{Case: "enabled no region", ExpectedString: "company", ExpectedEnabled: true, Profile: "company"},
|
||||
{Case: "enabled with region", ExpectedString: "company@eu-west", ExpectedEnabled: true, Profile: "company", Region: "eu-west"},
|
||||
{
|
||||
|
@ -49,7 +52,9 @@ func TestAWSSegment(t *testing.T) {
|
|||
env.On("getFileContent", "/usr/home/.aws/config").Return("")
|
||||
env.On("homeDir", nil).Return("/usr/home")
|
||||
props := &properties{
|
||||
values: map[Property]interface{}{},
|
||||
values: map[Property]interface{}{
|
||||
DisplayDefault: tc.DisplayDefault,
|
||||
},
|
||||
}
|
||||
if tc.Template != "" {
|
||||
props.values[SegmentTemplate] = tc.Template
|
||||
|
|
|
@ -10,8 +10,6 @@ type python struct {
|
|||
const (
|
||||
// DisplayVirtualEnv shows or hides the virtual env
|
||||
DisplayVirtualEnv Property = "display_virtual_env"
|
||||
// DisplayDefaultEnv shows or hides the default env names (system/base)
|
||||
DisplayDefaultEnv Property = "display_default_env"
|
||||
)
|
||||
|
||||
func (p *python) string() string {
|
||||
|
@ -78,7 +76,7 @@ func (p *python) canUseVenvName(name string) bool {
|
|||
if name == "" || name == "." {
|
||||
return false
|
||||
}
|
||||
if p.language.props.getBool(DisplayDefaultEnv, true) {
|
||||
if p.language.props.getBool(DisplayDefault, true) {
|
||||
return true
|
||||
}
|
||||
invalidNames := [2]string{"system", "base"}
|
||||
|
|
|
@ -14,13 +14,13 @@ func TestPythonVirtualEnv(t *testing.T) {
|
|||
CondaDefaultEnvName string
|
||||
PyEnvName string
|
||||
DisplayVersion bool
|
||||
DisplayDefaultEnv bool
|
||||
DisplayDefault bool
|
||||
}{
|
||||
{Expected: "VENV", VirtualEnvName: "VENV"},
|
||||
{Expected: "CONDA", CondaEnvName: "CONDA"},
|
||||
{Expected: "CONDA", CondaDefaultEnvName: "CONDA"},
|
||||
{Expected: "", CondaDefaultEnvName: "base"},
|
||||
{Expected: "base", CondaDefaultEnvName: "base", DisplayDefaultEnv: true},
|
||||
{Expected: "base", CondaDefaultEnvName: "base", DisplayDefault: true},
|
||||
{Expected: "PYENV", PyEnvName: "PYENV"},
|
||||
{Expected: "PYENV 3.8.4", PyEnvName: "PYENV", DisplayVersion: true},
|
||||
}
|
||||
|
@ -39,7 +39,7 @@ func TestPythonVirtualEnv(t *testing.T) {
|
|||
values: map[Property]interface{}{
|
||||
DisplayVersion: tc.DisplayVersion,
|
||||
DisplayVirtualEnv: true,
|
||||
DisplayDefaultEnv: tc.DisplayDefaultEnv,
|
||||
DisplayDefault: tc.DisplayDefault,
|
||||
},
|
||||
}
|
||||
python := &python{}
|
||||
|
|
|
@ -29,13 +29,11 @@ const (
|
|||
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)
|
||||
showDefaultUser := s.props.getBool(DisplayDefault, true)
|
||||
defaultUser := s.props.getString(DefaultUserName, "")
|
||||
if !showDefaultUser && defaultUser == s.UserName {
|
||||
return false
|
||||
|
|
|
@ -43,7 +43,7 @@
|
|||
"background": "#2f2f2f",
|
||||
"properties": {
|
||||
"user_info_separator": "<#7a7a7a>\uf1fa</>",
|
||||
"display_default_user": false,
|
||||
"display_default": false,
|
||||
"user_color": "#77f5d6",
|
||||
"host_color": "#2EEFBF",
|
||||
"postfix": "<#7a7a7a> \ue0b1</>"
|
||||
|
|
Loading…
Reference in a new issue