Repository: JanDeDobbeleer/oh-my-posh
Pull request #559 (2021-03-22 18:26:10)

feat(language): disable when at home
### Prerequisites

- [ ] I have read and understand the `CONTRIBUTING` guide
- [ ] The commit message follows the [conventional commits][cc] guidelines
- [ ] Tests for the changes have been added (for bug fixes / features)
- [ ] Docs have been added / updated (for bug fixes / features)

### Description

[Description of the change]

[cc]: https://www.conventionalcommits.org/en/v1.0.0/#summary



Patch:
diff --git a/src/segment_language.go b/src/segment_language.go
index dac79a0a..9ea0f9b7 100644
--- a/src/segment_language.go
+++ b/src/segment_language.go
@@ -116,6 +116,9 @@ func (l *language) string() string {
 }
 
 func (l *language) enabled() bool {
+	if l.env.getcwd() == l.env.homeDir() {
+		return false
+	}
 	l.loadLanguageContext()
 	displayMode := l.props.getString(DisplayMode, DisplayModeFiles)
 	switch displayMode {


Test patch:
diff --git a/src/segment_dotnet_test.go b/src/segment_dotnet_test.go
index 6e501d00..edcb244e 100644
--- a/src/segment_dotnet_test.go
+++ b/src/segment_dotnet_test.go
@@ -26,6 +26,8 @@ func bootStrapDotnetTest(args *dotnetArgs) *dotnet {
 
 	env.On("hasFiles", "*.cs").Return(true)
 	env.On("getPathSeperator", nil).Return("")
+	env.On("getcwd", nil).Return("/usr/home/project")
+	env.On("homeDir", nil).Return("/usr/home")
 	props := &properties{
 		values: map[Property]interface{}{
 			DisplayVersion:               args.displayVersion,
diff --git a/src/segment_golang_test.go b/src/segment_golang_test.go
index 2cebb4f4..b7d8e18b 100755
--- a/src/segment_golang_test.go
+++ b/src/segment_golang_test.go
@@ -21,6 +21,8 @@ func TestGolang(t *testing.T) {
 		env.On("hasCommand", "go").Return(true)
 		env.On("runCommand", "go", []string{"version"}).Return(tc.Version, nil)
 		env.On("hasFiles", "*.go").Return(true)
+		env.On("getcwd", nil).Return("/usr/home/project")
+		env.On("homeDir", nil).Return("/usr/home")
 		props := &properties{
 			values: map[Property]interface{}{
 				DisplayVersion: true,
diff --git a/src/segment_java_test.go b/src/segment_java_test.go
index 55b7395b..e3b91feb 100755
--- a/src/segment_java_test.go
+++ b/src/segment_java_test.go
@@ -38,6 +38,8 @@ func TestJava(t *testing.T) {
 		env.On("hasCommand", "java").Return(true)
 		env.On("runCommand", "java", []string{"-Xinternalversion"}).Return(tc.Version, nil)
 		env.On("hasFiles", "pom.xml").Return(true)
+		env.On("getcwd", nil).Return("/usr/home/project")
+		env.On("homeDir", nil).Return("/usr/home")
 		if tc.JavaHomeEnabled {
 			env.On("getenv", "JAVA_HOME").Return("/usr/java")
 			env.On("hasCommand", "/usr/java/bin/java").Return(true)
diff --git a/src/segment_language_test.go b/src/segment_language_test.go
index 0db52859..14c5d9f7 100644
--- a/src/segment_language_test.go
+++ b/src/segment_language_test.go
@@ -22,6 +22,7 @@ type languageArgs struct {
 	expectedError      error
 	properties         map[Property]interface{}
 	matchesVersionFile matchesVersionFile
+	inHome             bool
 }
 
 func (l *languageArgs) hasvalue(value string, list []string) bool {
@@ -42,6 +43,13 @@ func bootStrapLanguageTest(args *languageArgs) *language {
 	for _, extension := range args.extensions {
 		env.On("hasFiles", extension).Return(args.hasvalue(extension, args.enabledExtensions))
 	}
+	home := "/usr/home"
+	cwd := "/usr/home/project"
+	if args.inHome {
+		cwd = home
+	}
+	env.On("getcwd", nil).Return(cwd)
+	env.On("homeDir", nil).Return(home)
 	props := &properties{
 		values: args.properties,
 	}
@@ -141,6 +149,25 @@ func TestLanguageEnabledOneExtensionFound(t *testing.T) {
 	assert.Equal(t, universion, lang.string(), "unicorn is available and uni files are found")
 }
 
+func TestLanguageDisabledInHome(t *testing.T) {
+	args := &languageArgs{
+		commands: []*cmd{
+			{
+				executable: "unicorn",
+				args:       []string{"--version"},
+				regex:      "(?P<version>.*)",
+			},
+		},
+		extensions:        []string{uni, corn},
+		enabledExtensions: []string{uni},
+		enabledCommands:   []string{"unicorn"},
+		version:           universion,
+		inHome:            true,
+	}
+	lang := bootStrapLanguageTest(args)
+	assert.False(t, lang.enabled())
+}
+
 func TestLanguageEnabledSecondExtensionFound(t *testing.T) {
 	args := &languageArgs{
 		commands: []*cmd{
diff --git a/src/segment_python_test.go b/src/segment_python_test.go
index feddeb0d..a2d197dc 100644
--- a/src/segment_python_test.go
+++ b/src/segment_python_test.go
@@ -35,6 +35,8 @@ func TestPythonVirtualEnv(t *testing.T) {
 		env.On("getenv", "CONDA_DEFAULT_ENV").Return(tc.CondaDefaultEnvName)
 		env.On("getenv", "PYENV_VERSION").Return(tc.PyEnvName)
 		env.On("getPathSeperator", nil).Return("")
+		env.On("getcwd", nil).Return("/usr/home/project")
+		env.On("homeDir", nil).Return("/usr/home")
 		props := &properties{
 			values: map[Property]interface{}{
 				DisplayVersion:    tc.DisplayVersion,
diff --git a/src/segment_ruby_test.go b/src/segment_ruby_test.go
index a11faf70..dbc3f8ec 100755
--- a/src/segment_ruby_test.go
+++ b/src/segment_ruby_test.go
@@ -96,6 +96,8 @@ func TestRuby(t *testing.T) {
 		env.On("hasFiles", "*.rb").Return(tc.HasRubyFiles)
 		env.On("hasFiles", "Rakefile").Return(tc.HasRakeFile)
 		env.On("hasFiles", "Gemfile").Return(tc.HasGemFile)
+		env.On("getcwd", nil).Return("/usr/home/project")
+		env.On("homeDir", nil).Return("/usr/home")
 		props := &properties{
 			values: map[Property]interface{}{
 				DisplayVersion: tc.DisplayVersion,