Skip to content

Commit

Permalink
Only default home dir abbreviation to $true on Linux/macOS
Browse files Browse the repository at this point in the history
If enabled, always substitute ~ for the home dir path on all OSs.
  • Loading branch information
rkeithhill committed Oct 20, 2020
1 parent d94feed commit 45531e5
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/PoshGitTypes.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions src/Utils.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}

Expand Down
7 changes: 6 additions & 1 deletion test/Shared.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,12 @@ function global:Convert-NativeLineEnding([string]$content, [switch]$SplitLines)
}

function GetHomePath() {
$Home
if ($GitPromptSettings.DefaultPromptAbbreviateHomeDirectory) {
"~"
}
else {
$Home
}
}

function GetHomeRelPath([string]$Path) {
Expand Down

0 comments on commit 45531e5

Please sign in to comment.