Repository: JanDeDobbeleer/oh-my-posh
Pull request #3367 (2023-01-14 09:54:56)

saturnay
### Prerequisites

- [x] I have read and understood the [contributing guide][CONTRIBUTING.md]
- [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

- fix(git): fallback to origin for remote URL
- refactor(ansi): remove background color on transparent
- fix(ansi): do not end coloring on identical colors

<!---

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



Patch:
diff --git a/src/ansi/ansi_writer.go b/src/ansi/ansi_writer.go
index f2f1b337..e56603a6 100644
--- a/src/ansi/ansi_writer.go
+++ b/src/ansi/ansi_writer.go
@@ -57,6 +57,7 @@ const (
 	colorise       = "\x1b[%sm"
 	transparent    = "\x1b[0m\x1b[%s;49m\x1b[7m"
 	transparentEnd = "\x1b[27m"
+	backgroundEnd  = "\x1b[49m"
 
 	AnsiRegex = "[\u001B\u009B][[\\]()#;?]*(?:(?:(?:[a-zA-Z\\d]*(?:;[a-zA-Z\\d]*)*)?\u0007)|(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PRZcf-ntqry=><~]))"
 
@@ -408,6 +409,12 @@ func (w *Writer) writeColorOverrides(match map[string]string, background string,
 	if match[ANCHOR] == colorStyle.AnchorEnd {
 		// make sure to reset the colors if needed
 		position += len([]rune(colorStyle.AnchorEnd)) - 1
+
+		// do not reset when colors are identical
+		if w.currentBackground == w.background && w.currentForeground == w.foreground {
+			return
+		}
+
 		// do not restore colors at the end of the string, we print it anyways
 		if position == len(w.runes)-1 {
 			return
@@ -481,13 +488,13 @@ func (w *Writer) writeColorOverrides(match map[string]string, background string,
 	if w.currentBackground != w.background {
 		// end the colors in case we have a transparent background
 		if w.currentBackground.IsTransparent() {
-			w.writeEscapedAnsiString(colorStyle.End)
+			w.writeEscapedAnsiString(backgroundEnd)
 		} else {
 			w.writeEscapedAnsiString(fmt.Sprintf(colorise, w.currentBackground))
 		}
 	}
 
-	if w.currentForeground != w.foreground || w.currentBackground.IsTransparent() {
+	if w.currentForeground != w.foreground {
 		w.writeEscapedAnsiString(fmt.Sprintf(colorise, w.currentForeground))
 	}
 
diff --git a/src/segments/git.go b/src/segments/git.go
index 0f90b225..c0540ebb 100644
--- a/src/segments/git.go
+++ b/src/segments/git.go
@@ -170,7 +170,7 @@ func (g *Git) Enabled() bool {
 		g.Working = &GitStatus{}
 		g.Staging = &GitStatus{}
 	}
-	if len(g.Upstream) != 0 && g.props.GetBool(FetchUpstreamIcon, false) {
+	if g.props.GetBool(FetchUpstreamIcon, false) {
 		g.UpstreamIcon = g.getUpstreamIcon()
 	}
 	return true
@@ -674,7 +674,7 @@ func (g *Git) WorktreeCount() int {
 func (g *Git) getRemoteURL() string {
 	upstream := regex.ReplaceAllString("/.*", g.Upstream, "")
 	if len(upstream) == 0 {
-		return g.getGitCommandOutput("remote", "get-url", "origin")
+		upstream = "origin"
 	}
 	cfg, err := ini.Load(g.rootDir + "/config")
 	if err != nil {
diff --git a/website/static/install.ps1 b/website/static/install.ps1
index 7dc98bc1..7fa2b013 100644
--- a/website/static/install.ps1
+++ b/website/static/install.ps1
@@ -38,7 +38,7 @@ switch ($arch) {
             $installer = "install-386.exe"
         }
     }
-    12 { $installer = "install-amd64.exe" } # x64 emulated on Surface Pro X
+    12 { $installer = "install-arm64.exe" } # Surface Pro X
 }
 
 if ($installer -eq '') {


Test patch:
diff --git a/src/ansi/ansi_writer_hyperlink_test.go b/src/ansi/ansi_writer_hyperlink_test.go
index c384acf9..7e5067c7 100644
--- a/src/ansi/ansi_writer_hyperlink_test.go
+++ b/src/ansi/ansi_writer_hyperlink_test.go
@@ -44,7 +44,7 @@ func TestGenerateHyperlinkWithUrl(t *testing.T) {
 		{
 			Text:      "in <accent><b>pwsh </b></> ",
 			ShellName: shell.PWSH,
-			Expected:  "\x1b[47m\x1b[30min \x1b[0m\x1b[30m\x1b[1mpwsh \x1b[22m\x1b[47m \x1b[0m",
+			Expected:  "\x1b[47m\x1b[30min \x1b[49m\x1b[1mpwsh \x1b[22m\x1b[47m \x1b[0m",
 		},
 		{Text: "«google»(http://www.google.be)", ShellName: shell.ZSH, Expected: "%{\x1b[47m%}%{\x1b[30m%}%{\x1b]8;;http://www.google.be\x1b\\%}google%{\x1b]8;;\x1b\\%}%{\x1b[0m%}"},
 		{Text: "«google»(http://www.google.be)", ShellName: shell.PWSH, Expected: "\x1b[47m\x1b[30m\x1b]8;;http://www.google.be\x1b\\google\x1b]8;;\x1b\\\x1b[0m"},
diff --git a/src/ansi/ansi_writer_test.go b/src/ansi/ansi_writer_test.go
index e3ea921c..886374b0 100644
--- a/src/ansi/ansi_writer_test.go
+++ b/src/ansi/ansi_writer_test.go
@@ -17,6 +17,12 @@ func TestWriteANSIColors(t *testing.T) {
 		Parent             *Colors
 		TerminalBackground string
 	}{
+		{
+			Case:     "Inline override identical",
+			Input:    "\ue0a0saturnay <red>↑</>1",
+			Expected: "\x1b[31m\ue0a0saturnay ↑1\x1b[0m",
+			Colors:   &Colors{Foreground: "red", Background: Transparent},
+		},
 		{
 			Case:     "Bold",
 			Input:    "<b>test</b>",
@@ -99,7 +105,7 @@ func TestWriteANSIColors(t *testing.T) {
 		{
 			Case:     "Inherit no parent background",
 			Input:    "hello <,parentBackground>world</>",
-			Expected: "\x1b[47m\x1b[30mhello \x1b[0m\x1b[30mworld\x1b[0m",
+			Expected: "\x1b[47m\x1b[30mhello \x1b[49mworld\x1b[0m",
 			Colors:   &Colors{Foreground: "black", Background: "white"},
 		},
 		{