Repository: JanDeDobbeleer/oh-my-posh
Pull request #4836 (2024-04-14 04:23:27)

fix: prompt termination in devious-diamonds theme
The " \b" in this template was causing issues with non-deletable characters when you used tab to pop up suggestions in zsh. The approach of inserting an invisible character if not root preserves the trailing diamond without introducing spacing issues.

### Prerequisites

- [✔] I have read and understood the [contributing guide][CONTRIBUTING.md].
- [ ✔] The commit message follows the [conventional commits][cc] guidelines.
- [ n/a] Tests for the changes have been added (for bug fixes / features).
- [ n/a] Docs have been added/updated (for bug fixes / features).

### Description

<!---

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.

-->

[CONTRIBUTING.md]: https://github.com/JanDeDobbeleer/oh-my-posh/blob/main/CONTRIBUTING.md
[cc]: https://www.conventionalcommits.org/en/v1.0.0/#summary


Bondrake: Background: the edited section exists to provide this functionality of switching to a red background and displaying a lightning symbol when you're root.
![image](https://github.com/JanDeDobbeleer/oh-my-posh/assets/11696/1d2110ae-95a1-4131-a57a-90bc754652d8)

Bondrake: The problem with the way it adds a backspace is that it causes this issue where I've entered "wh<tab>" and get the wh duplicated and then can't delete the first wh (e.g. with Ctrl+U or repeated backspace)
![image](https://github.com/JanDeDobbeleer/oh-my-posh/assets/11696/ea700aa0-ca2b-457d-a135-c48043a5b559)

If you just remove the "\b" you get this though, where the trailing diamond isn't preserved
![image](https://github.com/JanDeDobbeleer/oh-my-posh/assets/11696/70e28603-8ed4-4537-be4a-344f30800218)

Thus this fix of adding the invisible character to preserve the intended display style without side effects.

Patch:
diff --git a/src/segments/firebase.go b/src/segments/firebase.go
index 9b989d40..fc0e58e3 100644
--- a/src/segments/firebase.go
+++ b/src/segments/firebase.go
@@ -4,6 +4,7 @@ import (
 	"encoding/json"
 	"errors"
 	"path/filepath"
+	"strings"
 
 	"github.com/jandedobbeleer/oh-my-posh/src/platform"
 	"github.com/jandedobbeleer/oh-my-posh/src/properties"
@@ -53,7 +54,7 @@ func (f *Firebase) Enabled() bool {
 	// Test if the current directory is a project path
 	// and if it is, return the project name
 	for key, value := range data.ActiveProject {
-		if key == f.env.Pwd() {
+		if strings.HasPrefix(f.env.Pwd(), key) {
 			f.Project = value
 			return true
 		}
diff --git a/themes/devious-diamonds.omp.yaml b/themes/devious-diamonds.omp.yaml
index ffda11a8..a99211b1 100644
--- a/themes/devious-diamonds.omp.yaml
+++ b/themes/devious-diamonds.omp.yaml
@@ -234,7 +234,7 @@ blocks:
         foreground: white
         properties:
           root_icon: 
-        template: "{{ if and .Root ( not .Segments.Path.Writable ) }} {{ end }}{{ if and .Root .Segments.Path.Writable }}  {{ end }} \b"
+        template: "{{ if not .Root }}\u2800{{ end }}{{ if and .Root ( not .Segments.Path.Writable ) }} {{ end }}{{ if and .Root .Segments.Path.Writable }}  {{ end }}"
 console_title_template: "{{ .Folder }}"
 palette:
   black: "#1B1A23"


Test patch:
diff --git a/src/segments/firebase_test.go b/src/segments/firebase_test.go
index 6b04097a..e24c428f 100644
--- a/src/segments/firebase_test.go
+++ b/src/segments/firebase_test.go
@@ -10,22 +10,31 @@ import (
 )
 
 func TestFirebaseSegment(t *testing.T) {
+	config := `{
+		"activeProjects": {
+			"path": "project-name"
+		}
+	}`
 	cases := []struct {
 		Case            string
-		CfgData         string
 		ActiveConfig    string
+		ActivePath      string
 		ExpectedEnabled bool
 		ExpectedString  string
 	}{
 		{
 			Case:            "happy path",
 			ExpectedEnabled: true,
-			ActiveConfig: `{
-				"activeProjects": {
-					"path": "project-name"
-				}
-			}`,
-			ExpectedString: "project-name",
+			ActiveConfig:    config,
+			ActivePath:      "path",
+			ExpectedString:  "project-name",
+		},
+		{
+			Case:            "happy subpath",
+			ExpectedEnabled: true,
+			ActiveConfig:    config,
+			ActivePath:      "path/subpath",
+			ExpectedString:  "project-name",
 		},
 		{
 			Case:            "no active config",
@@ -46,7 +55,7 @@ func TestFirebaseSegment(t *testing.T) {
 	for _, tc := range cases {
 		env := new(mock.MockedEnvironment)
 		env.On("Home").Return("home")
-		env.On("Pwd").Return("path")
+		env.On("Pwd").Return(tc.ActivePath)
 		fcPath := filepath.Join("home", ".config", "configstore", "firebase-tools.json")
 		env.On("FileContent", fcPath).Return(tc.ActiveConfig)
 		env.On("Error", mock2.Anything).Return()