Repository: JanDeDobbeleer/oh-my-posh
Pull request #4277 (2023-09-22 20:18:08)

docs: Updating Unsigned Scripts Info
Updating fix for issues running unsigned scripts

### 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

<!--
copilot:summary
-->
### <samp>🤖 Generated by Copilot at b158f7f</samp>

Improved `Set-ExecutionPolicy` command in installation instructions for oh-my-posh. Added `-ExecutionPolicy` and `-Scope` parameters to avoid conflicts and clarify the command.

### How

<!--
copilot:walkthrough
-->
### <samp>🤖 Generated by Copilot at b158f7f</samp>

*  Add the `-ExecutionPolicy` and `-Scope` parameters to the `Set-ExecutionPolicy` command in the installation instructions for Windows PowerShell ([link](https://github.com/JanDeDobbeleer/oh-my-posh/pull/4277/files?diff=unified&w=0#diff-bfb275d8f295325f4e636f8ffe143c735c0f0c17e1bde1ed2ec51ff2933683edL154-R154))

<!---

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


CesarGBkR: Updating fix for issues running unsigned scripts

Patch:
diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json
index 5ee3efd0..030098be 100644
--- a/.devcontainer/devcontainer.json
+++ b/.devcontainer/devcontainer.json
@@ -59,7 +59,7 @@
       "extensions": [
         "actboy168.tasks",
         "eamodio.gitlens",
-        "bungcip.better-toml",
+        "tamasfe.even-better-toml",
         "davidanson.vscode-markdownlint",
         "editorconfig.editorconfig",
         "esbenp.prettier-vscode",
diff --git a/.vscode/extensions.json b/.vscode/extensions.json
index 20129c66..7f6664eb 100644
--- a/.vscode/extensions.json
+++ b/.vscode/extensions.json
@@ -6,7 +6,7 @@
     "esbenp.prettier-vscode",
     "davidanson.vscode-markdownlint",
     "yzhang.markdown-all-in-one",
-    "bungcip.better-toml",
+    "tamasfe.even-better-toml",
     "redhat.vscode-yaml"
   ]
 }
diff --git a/src/ansi/ansi_writer.go b/src/ansi/ansi_writer.go
index 820ad1a2..7f1ff9f9 100644
--- a/src/ansi/ansi_writer.go
+++ b/src/ansi/ansi_writer.go
@@ -488,12 +488,15 @@ func (w *Writer) endColorOverride(position int) int {
 	// make sure to reset the colors if needed
 	position += len([]rune(resetStyle.AnchorEnd)) - 1
 
-	// reset colors to previous when we have > 2 in stack
-	// - first is always the starting colors used in Write()
-	// - second is the first override
-	// as soon as we have  more than 2, we can pop the last one
+	// do not restore colors at the end of the string, we print it anyways
+	if position == len(w.runes)-1 {
+		return position
+	}
+
+	// reset colors to previous when we have >= 2 in stack
+	// as soon as we have  more than 1, we can pop the last one
 	// and print the previous override as it wasn't ended yet
-	if w.current.Len() >= 3 {
+	if w.current.Len() >= 2 {
 		fg := w.current.Foreground()
 		bg := w.current.Background()
 
@@ -515,11 +518,6 @@ func (w *Writer) endColorOverride(position int) int {
 		return position
 	}
 
-	// do not restore colors at the end of the string, we print it anyways
-	if position == len(w.runes)-1 {
-		return position
-	}
-
 	if w.transparent {
 		w.writeEscapedAnsiString(transparentEnd)
 	}
diff --git a/src/segments/git.go b/src/segments/git.go
index 7450dc34..cb77876c 100644
--- a/src/segments/git.go
+++ b/src/segments/git.go
@@ -778,6 +778,30 @@ func (g *Git) getRemoteURL() string {
 	return g.getGitCommandOutput("remote", "get-url", upstream)
 }
 
+func (g *Git) Remotes() map[string]string {
+	var remotes = make(map[string]string)
+
+	location := filepath.Join(g.rootDir, "config")
+	config := g.env.FileContent(location)
+	cfg, err := ini.Load([]byte(config))
+	if err != nil {
+		return remotes
+	}
+
+	for _, section := range cfg.Sections() {
+		if !strings.HasPrefix(section.Name(), "remote ") {
+			continue
+		}
+
+		name := strings.TrimPrefix(section.Name(), "remote ")
+		name = strings.Trim(name, "\"")
+		url := section.Key("url").String()
+		url = g.cleanUpstreamURL(url)
+		remotes[name] = url
+	}
+	return remotes
+}
+
 func (g *Git) getUntrackedFilesMode() string {
 	return g.getSwitchMode(UntrackedModes, "-u", "normal")
 }
diff --git a/website/docs/installation/prompt.mdx b/website/docs/installation/prompt.mdx
index 6f2bdf9d..9e95daac 100644
--- a/website/docs/installation/prompt.mdx
+++ b/website/docs/installation/prompt.mdx
@@ -151,7 +151,7 @@ New-Item -Path $PROFILE -Type File -Force
 ```
 
 In this scenario, it can also be that PowerShell blocks running local scripts. To solve that, set PowerShell
-to only require remote scripts to be signed using `Set-ExecutionPolicy RemoteSigned`, or [sign the profile][sign].
+to only require remote scripts to be signed using `Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope LocalMachine`, or [sign the profile][sign].
 :::
 
 Then add the following line.


Test patch:
diff --git a/src/ansi/ansi_writer_test.go b/src/ansi/ansi_writer_test.go
index c23ad58c..d344ba54 100644
--- a/src/ansi/ansi_writer_test.go
+++ b/src/ansi/ansi_writer_test.go
@@ -32,7 +32,7 @@ func TestWriteANSIColors(t *testing.T) {
 		{
 			Case:     "Bold with color override",
 			Input:    "<b><#ffffff>test</></b>",
-			Expected: "\x1b[1m\x1b[30m\x1b[38;2;255;255;255mtest\x1b[49m\x1b[30m\x1b[22m\x1b[0m",
+			Expected: "\x1b[1m\x1b[30m\x1b[38;2;255;255;255mtest\x1b[30m\x1b[22m\x1b[0m",
 			Colors:   &Colors{Foreground: "black", Background: ParentBackground},
 		},
 		{
@@ -41,7 +41,6 @@ func TestWriteANSIColors(t *testing.T) {
 			Expected: "\x1b[38;2;255;255;255m\x1b[1mtest\x1b[22m\x1b[0m",
 			Colors:   &Colors{Foreground: "black", Background: ParentBackground},
 		},
-
 		{
 			Case:     "Double override",
 			Input:    "<#ffffff>jan</>@<#ffffff>Jans-MBP</>",
diff --git a/src/segments/git_test.go b/src/segments/git_test.go
index e6f179dd..80710927 100644
--- a/src/segments/git_test.go
+++ b/src/segments/git_test.go
@@ -1050,3 +1050,58 @@ func TestGitCommit(t *testing.T) {
 		assert.Equal(t, tc.Expected, got, tc.Case)
 	}
 }
+
+func TestGitRemotes(t *testing.T) {
+	cases := []struct {
+		Case     string
+		Expected int
+		Config   string
+	}{
+		{
+			Case:     "Empty config file",
+			Expected: 0,
+		},
+		{
+			Case:     "Two remotes",
+			Expected: 2,
+			Config: `
+[remote "origin"]
+	url = git@github.com:JanDeDobbeleer/test.git
+	fetch = +refs/heads/*:refs/remotes/origin/*
+[remote "upstream"]
+	url = git@github.com:microsoft/test.git
+	fetch = +refs/heads/*:refs/remotes/upstream/*
+`,
+		},
+		{
+			Case:     "One remote",
+			Expected: 1,
+			Config: `
+[remote "origin"]
+	url = git@github.com:JanDeDobbeleer/test.git
+	fetch = +refs/heads/*:refs/remotes/origin/*
+`,
+		},
+		{
+			Case:     "Broken config",
+			Expected: 0,
+			Config:   "{{}}",
+		},
+	}
+
+	for _, tc := range cases {
+		env := new(mock.MockedEnvironment)
+		env.On("FileContent", "config").Return(tc.Config)
+
+		g := &Git{
+			scm: scm{
+				props:   properties.Map{},
+				realDir: "foo",
+				env:     env,
+			},
+		}
+
+		got := g.Remotes()
+		assert.Equal(t, tc.Expected, len(got), tc.Case)
+	}
+}