Repository: JanDeDobbeleer/oh-my-posh
Pull request #3384 (2023-01-20 20:33:22)

friyay
### 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

- feat(config): support for 5 code point glyphs in export
- fix(git): do not process remote when empty
- fix(git): clean ssh remote url correctly

<!---

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/engine/config.go b/src/engine/config.go
index 46c96057..d53ea1f4 100644
--- a/src/engine/config.go
+++ b/src/engine/config.go
@@ -235,13 +235,54 @@ func (cfg *Config) backup() {
 }
 
 func escapeGlyphs(s string) string {
+	shouldExclude := func(r rune) bool {
+		if r < 0x1000 { // Basic Multilingual Plane
+			return true
+		}
+		if r > 0x1F600 && r < 0x1F64F { // Emoticons
+			return true
+		}
+		if r > 0x1F300 && r < 0x1F5FF { // Misc Symbols and Pictographs
+			return true
+		}
+		if r > 0x1F680 && r < 0x1F6FF { // Transport and Map
+			return true
+		}
+		if r > 0x2600 && r < 0x26FF { // Misc symbols
+			return true
+		}
+		if r > 0x2700 && r < 0x27BF { // Dingbats
+			return true
+		}
+		if r > 0xFE00 && r < 0xFE0F { // Variation Selectors
+			return true
+		}
+		if r > 0x1F900 && r < 0x1F9FF { // Supplemental Symbols and Pictographs
+			return true
+		}
+		if r > 0x1F1E6 && r < 0x1F1FF { // Flags
+			return true
+		}
+		return false
+	}
+
 	var builder strings.Builder
 	for _, r := range s {
-		// exclude regular characters and emoji
-		if r < 0x1000 || r > 0x10000 {
+		// exclude regular characters and emojis
+		if shouldExclude(r) {
 			builder.WriteRune(r)
 			continue
 		}
+
+		if r > 0x10000 {
+			// calculate surrogate pairs
+			one := 0xd800 + (((r - 0x10000) >> 10) & 0x3ff)
+			two := 0xdc00 + ((r - 0x10000) & 0x3ff)
+			quoted := fmt.Sprintf("\\u%04x\\u%04x", one, two)
+			builder.WriteString(quoted)
+			continue
+		}
+
 		quoted := fmt.Sprintf("\\u%04x", r)
 		builder.WriteString(quoted)
 	}
diff --git a/src/segments/git.go b/src/segments/git.go
index c0540ebb..adc90302 100644
--- a/src/segments/git.go
+++ b/src/segments/git.go
@@ -384,13 +384,17 @@ func (g *Git) getUpstreamIcon() string {
 		if strings.HasPrefix(url, "http") {
 			return url
 		}
+		url = strings.TrimPrefix(url, "ssh://")
 		url = strings.TrimPrefix(url, "git://")
 		url = strings.TrimPrefix(url, "git@")
 		url = strings.TrimSuffix(url, ".git")
-		url = strings.ReplaceAll(url, ":", "/")
 		return fmt.Sprintf("https://%s", url)
 	}
+
 	g.RawUpstreamURL = g.getRemoteURL()
+	if len(g.RawUpstreamURL) == 0 {
+		return ""
+	}
 	g.UpstreamURL = cleanSSHURL(g.RawUpstreamURL)
 
 	// allow overrides first


Test patch:
diff --git a/src/engine/config_test.go b/src/engine/config_test.go
index 8a60c33a..fd69d02f 100644
--- a/src/engine/config_test.go
+++ b/src/engine/config_test.go
@@ -49,6 +49,7 @@ func TestEscapeGlyphs(t *testing.T) {
 		Input    string
 		Expected string
 	}{
+		{Input: "󰉋", Expected: "\\udb80\\ude4b"},
 		{Input: "a", Expected: "a"},
 		{Input: "\ue0b4", Expected: "\\ue0b4"},
 		{Input: "\ufd03", Expected: "\\ufd03"},
diff --git a/src/segments/git_test.go b/src/segments/git_test.go
index 223d796a..1fe9c088 100644
--- a/src/segments/git_test.go
+++ b/src/segments/git_test.go
@@ -593,6 +593,8 @@ func TestGitUpstream(t *testing.T) {
 		Expected string
 		Upstream string
 	}{
+		{Case: "No upstream", Expected: "", Upstream: ""},
+		{Case: "SSH url", Expected: "G", Upstream: "ssh://git@git.my.domain:3001/ADIX7/dotconfig.git"},
 		{Case: "GitHub", Expected: "GH", Upstream: "github.com/test"},
 		{Case: "Gitlab", Expected: "GL", Upstream: "gitlab.com/test"},
 		{Case: "Bitbucket", Expected: "BB", Upstream: "bitbucket.org/test"},