Repository: JanDeDobbeleer/oh-my-posh
Pull request #3997 (2023-06-26 07:57:38)

fix(node): invert .Mismatch logic
fix(node): invert .Mismatch logic

---
Stack created with [Sapling](https://sapling-scm.com). Best reviewed with [ReviewStack](https://reviewstack.dev/JanDeDobbeleer/oh-my-posh/pull/3997).
* #3998
* __->__ #3997


Patch:
diff --git a/src/segments/language.go b/src/segments/language.go
index 1cc89ce2..e2b7d24b 100644
--- a/src/segments/language.go
+++ b/src/segments/language.go
@@ -140,8 +140,13 @@ func (l *language) Enabled() bool {
 	}
 
 	if l.matchesVersionFile != nil {
-		l.version.Expected, l.Mismatch = l.matchesVersionFile()
+		expected, match := l.matchesVersionFile()
+		if !match {
+			l.Mismatch = true
+			l.Expected = expected
+		}
 	}
+
 	return enabled
 }
 
diff --git a/website/docs/segments/node.mdx b/website/docs/segments/node.mdx
index e8984784..e3b77423 100644
--- a/website/docs/segments/node.mdx
+++ b/website/docs/segments/node.mdx
@@ -10,16 +10,18 @@ Display the currently active [Node.js][node-js] version.
 
 ## Sample Configuration
 
-import Config from '@site/src/components/Config.js';
+import Config from "@site/src/components/Config.js";
 
-<Config data={{
-  "type": "node",
-  "style": "powerline",
-  "powerline_symbol": "\uE0B0",
-  "foreground": "#ffffff",
-  "background": "#6CA35E",
-  "template": " \uE718 {{ .Full }} "
-}}/>
+<Config
+  data={{
+    type: "node",
+    style: "powerline",
+    powerline_symbol: "\uE0B0",
+    foreground: "#ffffff",
+    background: "#6CA35E",
+    template: " \uE718 {{ .Full }} ",
+  }}
+/>
 
 ## Properties
 
@@ -55,7 +57,7 @@ import Config from '@site/src/components/Config.js';
 | `.URL`                | `string`  | URL of the version info / release notes                             |
 | `.Error`              | `string`  | error encountered when fetching the version string                  |
 | `.PackageManagerIcon` | `string`  | the Yarn or NPM icon when setting `fetch_package_manager` to `true` |
-| `.Mismatch`           | `boolean` | if the version in `.nvmrc` matches with `.Full`                     |
+| `.Mismatch`           | `boolean` | true if the version in `.nvmrc` is not equal to `.Full`             |
 | `.Expected`           | `string`  | the expected version set in `.nvmrc`                                |
 
 [go-text-template]: https://golang.org/pkg/text/template/
diff --git a/website/static/install.sh b/website/static/install.sh
index 0bd23451..e4b7090b 100755
--- a/website/static/install.sh
+++ b/website/static/install.sh
@@ -81,7 +81,7 @@ validate_install_directory() {
 
     # check if we can write to the install directory
     if [ ! -w $install_dir ]; then
-        error "Cannot write to ${install_dir}. Please run the script with sudo and try again:\n  sudo ./install.sh"
+        error "Cannot write to ${install_dir}. Please run the script with sudo and try again:\n  curl -s https://ohmyposh.dev/install.sh | sudo bash -s\n\nAlternatively, you can set a different directory and try again: \n  curl -s https://ohmyposh.dev/install.sh | bash -s -- -d {directory}"
     fi
 
     # check if the directory is in the PATH


Test patch:
diff --git a/src/segments/language_test.go b/src/segments/language_test.go
index e027d5d6..01ffd5ef 100644
--- a/src/segments/language_test.go
+++ b/src/segments/language_test.go
@@ -157,6 +157,31 @@ func TestLanguageEnabledOneExtensionFound(t *testing.T) {
 	assert.Equal(t, "unicorn", lang.Executable, "unicorn was used")
 }
 
+func TestLanguageEnabledMismatch(t *testing.T) {
+	expectedVersion := "1.2.009"
+
+	args := &languageArgs{
+		commands: []*cmd{
+			{
+				executable: "unicorn",
+				args:       []string{"--version"},
+				regex:      "(?P<version>.*)",
+			},
+		},
+		extensions:        []string{uni, corn},
+		enabledExtensions: []string{uni},
+		enabledCommands:   []string{"unicorn"},
+		version:           universion,
+		matchesVersionFile: func() (string, bool) {
+			return expectedVersion, false
+		},
+	}
+	lang := bootStrapLanguageTest(args)
+	assert.True(t, lang.Enabled())
+	assert.Equal(t, expectedVersion, lang.Expected, "the expected unicorn version is 1.2.009")
+	assert.True(t, lang.Mismatch, "we require a different version of unicorn")
+}
+
 func TestLanguageDisabledInHome(t *testing.T) {
 	args := &languageArgs{
 		commands: []*cmd{