Repository: JanDeDobbeleer/oh-my-posh
Pull request #3290 (2023-01-02 19:03:40)

fix(fish): do not fix fish bug for hyperlinks
### 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

<!--TemplateBody-->

<!---

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/color/ansi.go b/src/color/ansi.go
index d091c13c..82848743 100644
--- a/src/color/ansi.go
+++ b/src/color/ansi.go
@@ -48,7 +48,7 @@ type Ansi struct {
 	format                string
 }
 
-func (a *Ansi) Init(shellName, goos string) {
+func (a *Ansi) Init(shellName string) {
 	a.shell = shellName
 	switch shellName {
 	case shell.ZSH:
@@ -125,6 +125,9 @@ func (a *Ansi) Init(shellName, goos string) {
 		a.colorTransparent = "\x1b[%s;49m\x1b[7m%s\x1b[0m"
 		a.escapeLeft = ""
 		a.escapeRight = ""
+		// when in fish on Linux, it seems hyperlinks ending with \\ print a \
+		// unlike on macOS. However, this is a fish bug, so do not try to fix it here:
+		// https://github.com/JanDeDobbeleer/oh-my-posh/pull/3288#issuecomment-1369137068
 		a.hyperlink = "\x1b]8;;%s\x1b\\%s\x1b]8;;\x1b\\"
 		a.hyperlinkRegex = "(?P<STR>\x1b]8;;(.+)\x1b\\\\\\\\?(?P<TEXT>.+)\x1b]8;;\x1b\\\\)"
 		a.osc99 = "\x1b]9;9;\"%s\"\x1b\\"
@@ -139,17 +142,10 @@ func (a *Ansi) Init(shellName, goos string) {
 		a.dimmed = "\x1b[2m%s\x1b[22m"
 		a.strikethrough = "\x1b[9m%s\x1b[29m"
 	}
-	// see https://github.com/JanDeDobbeleer/oh-my-posh/issues/3287
-	// when in fish on Linux, it seems hyperlinks ending with \\ prints a \
-	// unlike on macOS
-	if shellName == shell.FISH && goos == "linux" {
-		a.hyperlink = "\x1b]8;;%s\x1b%s\x1b]8;;\x1b\\"
-		a.hyperlinkRegex = "(?P<STR>\x1b]8;;(.+)\x1b?(?P<TEXT>.+)\x1b]8;;\x1b\\\\)"
-	}
 }
 
 func (a *Ansi) InitPlain() {
-	a.Init(shell.PLAIN, "")
+	a.Init(shell.PLAIN)
 }
 
 func (a *Ansi) GenerateHyperlink(text string) string {
diff --git a/src/engine/new.go b/src/engine/new.go
index 0caf7163..2eec953a 100644
--- a/src/engine/new.go
+++ b/src/engine/new.go
@@ -26,7 +26,7 @@ func New(flags *platform.Flags) *Engine {
 			Ansi: ansi,
 		}
 	} else {
-		ansi.Init(env.Shell(), env.GOOS())
+		ansi.Init(env.Shell())
 		writerColors := cfg.MakeColors()
 		writer = &color.AnsiWriter{
 			Ansi:               ansi,


Test patch:
diff --git a/src/color/ansi_test.go b/src/color/ansi_test.go
index ccc5da76..ff56fd73 100644
--- a/src/color/ansi_test.go
+++ b/src/color/ansi_test.go
@@ -20,7 +20,7 @@ func TestGenerateHyperlinkNoUrl(t *testing.T) {
 	}
 	for _, tc := range cases {
 		a := Ansi{}
-		a.Init(tc.ShellName, "")
+		a.Init(tc.ShellName)
 		hyperlinkText := a.GenerateHyperlink(tc.Text)
 		assert.Equal(t, tc.Expected, hyperlinkText)
 	}
@@ -53,7 +53,7 @@ func TestGenerateHyperlinkWithUrl(t *testing.T) {
 	}
 	for _, tc := range cases {
 		a := Ansi{}
-		a.Init(tc.ShellName, "")
+		a.Init(tc.ShellName)
 		hyperlinkText := a.GenerateHyperlink(tc.Text)
 		assert.Equal(t, tc.Expected, hyperlinkText)
 	}
@@ -71,7 +71,7 @@ func TestGenerateHyperlinkWithUrlNoName(t *testing.T) {
 	}
 	for _, tc := range cases {
 		a := Ansi{}
-		a.Init(tc.ShellName, "")
+		a.Init(tc.ShellName)
 		hyperlinkText := a.GenerateHyperlink(tc.Text)
 		assert.Equal(t, tc.Expected, hyperlinkText)
 	}
@@ -115,7 +115,7 @@ func TestGenerateFileLink(t *testing.T) {
 	}
 	for _, tc := range cases {
 		a := Ansi{}
-		a.Init(shell.PWSH, "")
+		a.Init(shell.PWSH)
 		hyperlinkText := a.GenerateHyperlink(tc.Text)
 		assert.Equal(t, tc.Expected, hyperlinkText)
 	}
diff --git a/src/color/text_test.go b/src/color/text_test.go
index ff329a9c..e192a693 100644
--- a/src/color/text_test.go
+++ b/src/color/text_test.go
@@ -37,7 +37,7 @@ func TestMeasureText(t *testing.T) {
 	for _, shell := range shells {
 		for _, tc := range cases {
 			ansi := &Ansi{}
-			ansi.Init(shell, "")
+			ansi.Init(shell)
 			tmpl := &template.Text{
 				Template: tc.Template,
 				Env:      env,
diff --git a/src/color/writer_test.go b/src/color/writer_test.go
index 2aeb9fe1..4b92bbcb 100644
--- a/src/color/writer_test.go
+++ b/src/color/writer_test.go
@@ -174,7 +174,7 @@ func TestWriteANSIColors(t *testing.T) {
 
 	for _, tc := range cases {
 		ansi := &Ansi{}
-		ansi.Init(shell.PWSH, "")
+		ansi.Init(shell.PWSH)
 		renderer := &AnsiWriter{
 			Ansi:               ansi,
 			ParentColors:       []*Color{tc.Parent},