From 8870a641d59b0d2db62180344f2174b5adc0bd20 Mon Sep 17 00:00:00 2001 From: Keith Hill Date: Fri, 29 Nov 2019 18:10:10 -0700 Subject: [PATCH] Fix #718 do not create HOME env var --- src/Utils.ps1 | 9 ++++++--- src/posh-git.psm1 | 3 --- test/DefaultPrompt.Tests.ps1 | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/Utils.ps1 b/src/Utils.ps1 index 955f13f0d..54d863bd1 100644 --- a/src/Utils.ps1 +++ b/src/Utils.ps1 @@ -291,11 +291,14 @@ function Get-PromptPath { $stringComparison = Get-PathStringComparison + # $HOME is defined by PowerShell on all platforms. If for some reason it isn't defined, use a fallback. + $homePath = if ($HOME) {$HOME} else {[System.Environment]::GetFolderPath([System.Environment+SpecialFolder]::UserProfile)} + # Abbreviate path by replacing beginning of path with ~ *iff* the path is under the user's home dir - if ($abbrevHomeDir -and $currentPath -and !$currentPath.Equals($Home, $stringComparison) -and - $currentPath.StartsWith($Home, $stringComparison)) { + if ($abbrevHomeDir -and $currentPath -and !$currentPath.Equals($homePath, $stringComparison) -and + $currentPath.StartsWith($homePath, $stringComparison)) { - $currentPath = "~" + $currentPath.SubString($Home.Length) + $currentPath = "~" + $currentPath.SubString($homePath.Length) } return $currentPath diff --git a/src/posh-git.psm1 b/src/posh-git.psm1 index 1f2b14d75..204dc9720 100644 --- a/src/posh-git.psm1 +++ b/src/posh-git.psm1 @@ -13,9 +13,6 @@ param([switch]$ForcePoshGitPrompt) . $PSScriptRoot\GitTabExpansion.ps1 . $PSScriptRoot\TortoiseGit.ps1 -if (!$Env:HOME) { $Env:HOME = "$Env:HOMEDRIVE$Env:HOMEPATH" } -if (!$Env:HOME) { $Env:HOME = "$Env:USERPROFILE" } - $IsAdmin = Test-Administrator # Get the default prompt definition. diff --git a/test/DefaultPrompt.Tests.ps1 b/test/DefaultPrompt.Tests.ps1 index 66a38abf0..0bbd91077 100644 --- a/test/DefaultPrompt.Tests.ps1 +++ b/test/DefaultPrompt.Tests.ps1 @@ -14,7 +14,7 @@ Describe 'Default Prompt Tests - NO ANSI' { Context 'Prompt with no Git summary' { It 'Returns the expected prompt string' { - Set-Location $env:HOME -ErrorAction Stop + Set-Location $HOME -ErrorAction Stop $res = [string](&$prompt *>&1) $res | Should BeExactly "$(Get-PromptConnectionInfo)$(GetHomePath)> " } @@ -152,7 +152,7 @@ Describe 'Default Prompt Tests - ANSI' { Context 'Prompt with no Git summary' { It 'Returns the expected prompt string' { - Set-Location $env:HOME -ErrorAction Stop + Set-Location $HOME -ErrorAction Stop $res = &$prompt $res | Should BeExactly "$(Get-PromptConnectionInfo)$(GetHomePath)> " }