Repository: JanDeDobbeleer/oh-my-posh
Pull request #1344 (2021-11-29 00:20:16)

Jdd main
### Prerequisites

- [X] I have read and understood the `CONTRIBUTING` guide
- [X] The commit message follows the [conventional commits][cc] guidelines
- [X] Tests for the changes have been added (for bug fixes/features)
- [X] Docs have been added / updated (for bug fixes/features)

### Description

feat(winreg): update return logic to allow successfully retrieved empty value to be used without fallback

fixing my commit tree with rebase and squash

fix schema.json winreg entries

undo erroneous prior fix to the segment contrib doc 

<!---

Tips:

If you're not comfortable with working with Git, we're working a guide (https://ohmyposh.dev/docs/contributing_git) to help you out.
Oh My Posh advises GitKraken (https://www.gitkraken.com/invite/nQmDPR9D) as your preferred cross platform Git GUI power tool.

-->

[cc]: https://www.conventionalcommits.org/en/v1.0.0/#summary



Patch:
diff --git a/src/segment_winreg.go b/src/segment_winreg.go
index cfb4c575..fc912cbe 100644
--- a/src/segment_winreg.go
+++ b/src/segment_winreg.go
@@ -32,11 +32,17 @@ func (wr *winreg) enabled() bool {
 
 	var err error
 	wr.Value, err = wr.env.getWindowsRegistryKeyValue(registryPath, registryKey)
-	if len(fallback) > 0 && (err != nil || len(wr.Value) == 0) {
+
+	if err == nil {
+		return true
+	}
+
+	if len(fallback) > 0 {
 		wr.Value = fallback
 		return true
 	}
-	return err == nil && len(wr.Value) > 0
+
+	return false
 }
 
 func (wr *winreg) string() string {
diff --git a/themes/schema.json b/themes/schema.json
index 030e762e..d93f5c7c 100644
--- a/themes/schema.json
+++ b/themes/schema.json
@@ -182,7 +182,7 @@
             "angular",
             "php",
             "wifi",
-            "regquery"
+            "winreg"
           ]
         },
         "style": {
@@ -1725,6 +1725,12 @@
                     "title": "Registry Key",
                     "description": "The key under he registry path to get (case insensitive).  If left blank, will get the value of the (Default) key in the registry_path",
                     "default": ""
+                  },
+                  "fallback": {
+                    "type":"string",
+                    "title":"Fallback value",
+                    "description":"Value to display if registry value cannot be retrieved",
+                    "default":""
                   }
                 }
               }


Test patch:
diff --git a/src/segment_winreg_test.go b/src/segment_winreg_test.go
index f5189a4b..5b58ad8b 100644
--- a/src/segment_winreg_test.go
+++ b/src/segment_winreg_test.go
@@ -44,20 +44,20 @@ func TestRegQueryEnabled(t *testing.T) {
 			ExpectedValue:   "cortana",
 		},
 		{
-			CaseDescription: "Fallback value on empty",
+			CaseDescription: "Empty string value (no error) should display empty string even in presence of fallback",
 			Path:            "HKLM\\Software\\Microsoft\\Windows NT\\CurrentVersion",
 			Key:             "InstallTime",
 			Output:          "",
 			Fallback:        "anaconda",
 			ExpectedSuccess: true,
-			ExpectedValue:   "anaconda",
+			ExpectedValue:   "",
 		},
 		{
-			CaseDescription: "Empty no fallback disabled",
+			CaseDescription: "Empty string value (no error) should display empty string",
 			Path:            "HKLM\\Software\\Microsoft\\Windows NT\\CurrentVersion",
 			Key:             "InstallTime",
 			Output:          "",
-			ExpectedSuccess: false,
+			ExpectedSuccess: true,
 			ExpectedValue:   "",
 		},
 	}