From 45531e5c7f341048dbd2515266696b37ec500651 Mon Sep 17 00:00:00 2001 From: Keith Hill Date: Mon, 19 Oct 2020 20:14:03 -0600 Subject: [PATCH] Only default home dir abbreviation to $true on Linux/macOS If enabled, always substitute ~ for the home dir path on all OSs. --- src/PoshGitTypes.ps1 | 2 +- src/Utils.ps1 | 6 +++--- test/Shared.ps1 | 7 ++++++- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/PoshGitTypes.ps1 b/src/PoshGitTypes.ps1 index ad54eb740..d9812f8bf 100644 --- a/src/PoshGitTypes.ps1 +++ b/src/PoshGitTypes.ps1 @@ -282,7 +282,7 @@ class PoshGitPromptSettings { [PoshGitTextSpan]$DefaultPromptDebug = [PoshGitTextSpan]::new(' [DBG]:', [ConsoleColor]::Magenta) [PoshGitTextSpan]$DefaultPromptSuffix = '$(">" * ($nestedPromptLevel + 1)) ' - [bool]$DefaultPromptAbbreviateHomeDirectory = $true + [bool]$DefaultPromptAbbreviateHomeDirectory = ($PSVersionTable.PSVersion.Major -gt 5) -and !$IsWindows [bool]$DefaultPromptAbbreviateGitDirectory = $false [bool]$DefaultPromptWriteStatusFirst = $false [bool]$DefaultPromptEnableTiming = $false diff --git a/src/Utils.ps1 b/src/Utils.ps1 index 193fa938e..3756a84d6 100644 --- a/src/Utils.ps1 +++ b/src/Utils.ps1 @@ -32,13 +32,13 @@ function Invoke-Utf8ConsoleCommand([ScriptBlock]$cmd) { # A native executable that writes to stderr AND has its stderr redirected will generate non-terminating # error records if the user has set $ErrorActionPreference to Stop. Override that value in this scope. $ErrorActionPreference = 'Continue' - + try { [Console]::OutputEncoding = [Text.Encoding]::UTF8 } catch [System.IO.IOException] {} & $cmd } finally { try { [Console]::OutputEncoding = $currentEncoding } catch [System.IO.IOException] {} - + # Clear out stderr output that was added to the $Error collection, putting those errors in a module variable if ($global:Error.Count -gt $errorCount) { $numNewErrors = $global:Error.Count - $errorCount @@ -285,7 +285,7 @@ function Get-PromptPath { # The latter is more desirable. $pathInfo = $ExecutionContext.SessionState.Path.CurrentLocation $currentPath = if ($pathInfo.Drive) { $pathInfo.Path } else { $pathInfo.ProviderPath } - if (!$settings -or !$currentPath -or $currentPath.Equals($Home, $stringComparison)) { + if (!$settings -or !$currentPath) { return $currentPath } diff --git a/test/Shared.ps1 b/test/Shared.ps1 index b72362f11..b4960319e 100644 --- a/test/Shared.ps1 +++ b/test/Shared.ps1 @@ -60,7 +60,12 @@ function global:Convert-NativeLineEnding([string]$content, [switch]$SplitLines) } function GetHomePath() { - $Home + if ($GitPromptSettings.DefaultPromptAbbreviateHomeDirectory) { + "~" + } + else { + $Home + } } function GetHomeRelPath([string]$Path) {