From c4db62c644f840be02862936509e5b323c44cde6 Mon Sep 17 00:00:00 2001 From: Jan De Dobbeleer Date: Sat, 31 Jul 2021 16:54:25 +0200 Subject: [PATCH] feat(language): allow enabling or disabling HOME folder closes #874 --- docs/docs/segment-crystal.md | 1 + docs/docs/segment-dart.md | 1 + docs/docs/segment-dotnet.md | 1 + docs/docs/segment-golang.md | 1 + docs/docs/segment-java.md | 1 + docs/docs/segment-julia.md | 1 + docs/docs/segment-node.md | 1 + docs/docs/segment-python.md | 1 + docs/docs/segment-ruby.md | 1 + docs/docs/segment-rust.md | 1 + src/segment_language.go | 7 +++++-- src/segment_language_test.go | 8 ++++---- 12 files changed, 19 insertions(+), 6 deletions(-) diff --git a/docs/docs/segment-crystal.md b/docs/docs/segment-crystal.md index b2797afa..9cf8ead6 100644 --- a/docs/docs/segment-crystal.md +++ b/docs/docs/segment-crystal.md @@ -25,6 +25,7 @@ Display the currently active crystal version. ## Properties +- home_enabled: `boolean` - display the segment in the HOME folder or not - defaults to `false` - display_version: `boolean` - display the julia version - defaults to `true` - display_error: `boolean` - show the error context when failing to retrieve the version information - defaults to `true` - missing_command_text: `string` - text to display when the command is missing - defaults to empty diff --git a/docs/docs/segment-dart.md b/docs/docs/segment-dart.md index e941a7ff..ddfe2475 100644 --- a/docs/docs/segment-dart.md +++ b/docs/docs/segment-dart.md @@ -25,6 +25,7 @@ Display the currently active dart version. ## Properties +- home_enabled: `boolean` - display the segment in the HOME folder or not - defaults to `false` - display_version: `boolean` - display the dart version - defaults to `true` - display_error: `boolean` - show the error context when failing to retrieve the version information - defaults to `true` - missing_command_text: `string` - text to display when the command is missing - defaults to empty diff --git a/docs/docs/segment-dotnet.md b/docs/docs/segment-dotnet.md index 0293edc4..60365943 100644 --- a/docs/docs/segment-dotnet.md +++ b/docs/docs/segment-dotnet.md @@ -25,6 +25,7 @@ Display the currently active .NET SDK version. ## Properties +- home_enabled: `boolean` - display the segment in the HOME folder or not - defaults to `false` - display_version: `boolean` - display the active version or not; useful if all you need is an icon indicating `dotnet` is present - defaults to `true` - display_error: `boolean` - show the error context when failing to retrieve the version information - defaults to `true` diff --git a/docs/docs/segment-golang.md b/docs/docs/segment-golang.md index b934c81f..10321d3f 100644 --- a/docs/docs/segment-golang.md +++ b/docs/docs/segment-golang.md @@ -25,6 +25,7 @@ Display the currently active golang version. ## Properties +- home_enabled: `boolean` - display the segment in the HOME folder or not - defaults to `false` - display_version: `boolean` - display the golang version - defaults to `true` - display_error: `boolean` - show the error context when failing to retrieve the version information - defaults to `true` - missing_command_text: `string` - text to display when the command is missing - defaults to empty diff --git a/docs/docs/segment-java.md b/docs/docs/segment-java.md index 10870634..f4cc85dd 100644 --- a/docs/docs/segment-java.md +++ b/docs/docs/segment-java.md @@ -25,6 +25,7 @@ Display the currently active java version. ## Properties +- home_enabled: `boolean` - display the segment in the HOME folder or not - defaults to `false` - display_version: `boolean` - display the java version - defaults to `true` - display_error: `boolean` - show the error context when failing to retrieve the version information - defaults to `true` - missing_command_text: `string` - text to display when the java command is missing - defaults to empty diff --git a/docs/docs/segment-julia.md b/docs/docs/segment-julia.md index 52c219ea..4b756083 100644 --- a/docs/docs/segment-julia.md +++ b/docs/docs/segment-julia.md @@ -25,6 +25,7 @@ Display the currently active julia version. ## Properties +- home_enabled: `boolean` - display the segment in the HOME folder or not - defaults to `false` - display_version: `boolean` - display the julia version - defaults to `true` - display_error: `boolean` - show the error context when failing to retrieve the version information - defaults to `true` - missing_command_text: `string` - text to display when the command is missing - defaults to empty diff --git a/docs/docs/segment-node.md b/docs/docs/segment-node.md index a9451121..04d5963a 100644 --- a/docs/docs/segment-node.md +++ b/docs/docs/segment-node.md @@ -25,6 +25,7 @@ Display the currently active node version. ## Properties +- home_enabled: `boolean` - display the segment in the HOME folder or not - defaults to `false` - display_version: `boolean` - display the node version - defaults to `true` - display_error: `boolean` - show the error context when failing to retrieve the version information - defaults to `true` - missing_command_text: `string` - text to display when the command is missing - defaults to empty diff --git a/docs/docs/segment-python.md b/docs/docs/segment-python.md index 7768a7f7..80fa7187 100644 --- a/docs/docs/segment-python.md +++ b/docs/docs/segment-python.md @@ -26,6 +26,7 @@ Supports conda, virtualenv and pyenv. ## Properties +- home_enabled: `boolean` - display the segment in the HOME folder or not - defaults to `false` - display_virtual_env: `boolean` - show the name of the virtualenv or not - defaults to `true` - display_default: `boolean` - show the name of the virtualenv when it's default (`system`, `base`) or not - defaults to `true` diff --git a/docs/docs/segment-ruby.md b/docs/docs/segment-ruby.md index 39ab86f3..e64fcf71 100644 --- a/docs/docs/segment-ruby.md +++ b/docs/docs/segment-ruby.md @@ -25,6 +25,7 @@ Display the currently active ruby version. ## Properties +- home_enabled: `boolean` - display the segment in the HOME folder or not - defaults to `false` - display_version: `boolean` - display the ruby version - defaults to `true` - display_error: `boolean` - show the error context when failing to retrieve the version information - defaults to `true` - missing_command_text: `string` - text to display when the command is missing - defaults to empty diff --git a/docs/docs/segment-rust.md b/docs/docs/segment-rust.md index 0cb8facc..30c222df 100644 --- a/docs/docs/segment-rust.md +++ b/docs/docs/segment-rust.md @@ -25,6 +25,7 @@ Display the currently active rust version. ## Properties +- home_enabled: `boolean` - display the segment in the HOME folder or not - defaults to `false` - display_version: `boolean` - display the rust version (`rustc --version`) - defaults to `true` - display_error: `boolean` - show the error context when failing to retrieve the version information - defaults to `true` - missing_command_text: `string` - text to display when the command is missing - defaults to empty diff --git a/src/segment_language.go b/src/segment_language.go index 7e0648f1..b48f9e43 100644 --- a/src/segment_language.go +++ b/src/segment_language.go @@ -90,6 +90,8 @@ const ( VersionMismatchColor Property = "version_mismatch_color" // EnableVersionMismatch displays empty string by default EnableVersionMismatch Property = "enable_version_mismatch" + // HomeEnabled displays the segment in the HOME folder or not + HomeEnabled Property = "home_enabled" ) func (l *language) string() string { @@ -119,10 +121,11 @@ func (l *language) enabled() bool { inHomeDir := func() bool { return l.env.getcwd() == l.env.homeDir() } - displayMode := l.props.getString(DisplayMode, DisplayModeFiles) - if inHomeDir() && displayMode != DisplayModeAlways { + homeEnabled := l.props.getBool(HomeEnabled, false) + if inHomeDir() && !homeEnabled { return false } + displayMode := l.props.getString(DisplayMode, DisplayModeFiles) l.loadLanguageContext() switch displayMode { case DisplayModeAlways: diff --git a/src/segment_language_test.go b/src/segment_language_test.go index afbb7ae8..a54c01fc 100644 --- a/src/segment_language_test.go +++ b/src/segment_language_test.go @@ -441,15 +441,15 @@ func TestLanguageHyperlinkEnabledLessParamInTemplate(t *testing.T) { func TestLanguageEnabledInHome(t *testing.T) { cases := []struct { Case string - DisplayMode string + HomeEnabled bool ExpectedEnabled bool }{ - {Case: "Always enabled", DisplayMode: DisplayModeAlways, ExpectedEnabled: true}, - {Case: "Context disabled", DisplayMode: DisplayModeContext, ExpectedEnabled: false}, + {Case: "Always enabled", HomeEnabled: true, ExpectedEnabled: true}, + {Case: "Context disabled", HomeEnabled: false, ExpectedEnabled: false}, } for _, tc := range cases { props := map[Property]interface{}{ - DisplayMode: tc.DisplayMode, + HomeEnabled: tc.HomeEnabled, } args := &languageArgs{ commands: []*cmd{