Repository: JanDeDobbeleer/oh-my-posh
Pull request #2051 (2022-04-07 06:46:53)

fix(path): agnoster unc path + powershell workingdirectory
### Prerequisites

- [x] I have read and understood the `CONTRIBUTING` guide
- [x] The commit message follows the [conventional commits][cc] guidelines
- [x] Tests for the changes have been added (for bug fixes/features)
- [ ] 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.

-->

[cc]: https://www.conventionalcommits.org/en/v1.0.0/#summary


lnu: For now, workingdirectory can be set safely only for FileSystem psprovider(works also with unc path)

Patch:
diff --git a/src/segments/path.go b/src/segments/path.go
index b418f52a..d8146803 100644
--- a/src/segments/path.go
+++ b/src/segments/path.go
@@ -238,7 +238,7 @@ func (pt *Path) getUniqueLettersPath() string {
 
 func (pt *Path) getAgnosterFullPath() string {
 	pwd := pt.getPwd()
-	if len(pwd) > 1 && string(pwd[0]) == pt.env.PathSeparator() {
+	for len(pwd) > 1 && string(pwd[0]) == pt.env.PathSeparator() {
 		pwd = pwd[1:]
 	}
 	return pt.replaceFolderSeparators(pwd)
diff --git a/src/shell/scripts/omp.ps1 b/src/shell/scripts/omp.ps1
index edf60ba0..abfdff26 100644
--- a/src/shell/scripts/omp.ps1
+++ b/src/shell/scripts/omp.ps1
@@ -1,26 +1,27 @@
-function global:Start-Utf8Process
-{
-	 param(
+function global:Start-Utf8Process {
+    param(
         [string] $FileName,
         [string] $Arguments
     )
 
-	$Process = New-Object System.Diagnostics.Process
-	$StartInfo = $Process.StartInfo
-	$StartInfo.StandardErrorEncoding = $StartInfo.StandardOutputEncoding = [System.Text.Encoding]::UTF8
-	$StartInfo.RedirectStandardError = $StartInfo.RedirectStandardInput = $StartInfo.RedirectStandardOutput = $true
-	$StartInfo.FileName = $filename
-	$StartInfo.Arguments = $Arguments
+    $Process = New-Object System.Diagnostics.Process
+    $StartInfo = $Process.StartInfo
+    $StartInfo.StandardErrorEncoding = $StartInfo.StandardOutputEncoding = [System.Text.Encoding]::UTF8
+    $StartInfo.RedirectStandardError = $StartInfo.RedirectStandardInput = $StartInfo.RedirectStandardOutput = $true
+    $StartInfo.FileName = $filename
+    $StartInfo.Arguments = $Arguments
     $StartInfo.UseShellExecute = $false
-    $StartInfo.WorkingDirectory = $PWD #when UseShellExecute=false, workingDirectory=""
+    if ($pwd.provider.name -eq "FileSystem") { #workingdirectory does not work with registry path
+        $StartInfo.WorkingDirectory = convert-path $pwd #when UseShellExecute=false, workingDirectory=""
+    }
     $StartInfo.CreateNoWindow = $true
-	$_ = $Process.Start();
-	$_ = $Process.WaitForExit();
+    $_ = $Process.Start();
+    $_ = $Process.WaitForExit();
     $stderr = $Process.StandardError.ReadToEnd().Trim()
     if ($stderr -ne '') {
         $Host.UI.WriteErrorLine($stderr)
     }
-	return $Process.StandardOutput.ReadToEnd()
+    return $Process.StandardOutput.ReadToEnd()
 }
 
 $env:POWERLINE_COMMAND = "oh-my-posh"
@@ -192,7 +193,8 @@ function global:Enable-PoshTransientPrompt {
         [Console]::OutputEncoding = [Text.Encoding]::UTF8
         try {
             [Microsoft.PowerShell.PSConsoleReadLine]::InvokePrompt()
-        } finally {
+        }
+        finally {
             [Microsoft.PowerShell.PSConsoleReadLine]::AcceptLine()
             [Console]::OutputEncoding = $previousOutputEncoding
         }


Test patch:
diff --git a/src/segments/path_test.go b/src/segments/path_test.go
index cab42b7b..75128f54 100644
--- a/src/segments/path_test.go
+++ b/src/segments/path_test.go
@@ -267,6 +267,9 @@ func TestAgnosterPathStyles(t *testing.T) {
 		{Style: Unique, Expected: "~ > a > ab > abcd", HomePath: "/usr/home", Pwd: "/usr/home/ab/abc/abcd", PathSeparator: "/", FolderSeparatorIcon: " > "},
 		{Style: Unique, Expected: "~ > a > .a > abcd", HomePath: "/usr/home", Pwd: "/usr/home/ab/.abc/abcd", PathSeparator: "/", FolderSeparatorIcon: " > "},
 		{Style: Unique, Expected: "~ > a > ab > abcd", HomePath: "/usr/home", Pwd: "/usr/home/ab/ab/abcd", PathSeparator: "/", FolderSeparatorIcon: " > "},
+
+		{Style: AgnosterShort, Expected: "localhost > c$", HomePath: homeBillWindows, Pwd: "\\\\localhost\\c$", PathSeparator: "\\", FolderSeparatorIcon: " > "},
+		{Style: AgnosterShort, Expected: "localhost\\c$", HomePath: homeBillWindows, Pwd: "\\\\localhost\\c$", PathSeparator: "\\", FolderSeparatorIcon: "\\"},
 	}
 	for _, tc := range cases {
 		env := new(mock.MockedEnvironment)