@@ -95,8 +95,16 @@ $global:GitPromptSettings = New-Object PSObject -Property @{
95
95
TruncatedBranchSuffix = ' ...'
96
96
}
97
97
98
- $currentUser = [Security.Principal.WindowsPrincipal ]([Security.Principal.WindowsIdentity ]::GetCurrent())
99
- $isAdminProcess = $currentUser.IsInRole ([Security.Principal.WindowsBuiltInRole ]::Administrator)
98
+ # PowerShell 5.x only runs on Windows so use .NET types to determine isAdminProcess
99
+ # Or if we are on v6 or higher, check the $IsWindows pre-defined variable.
100
+ if (($PSVersionTable.PSVersion.Major -le 5 ) -or $IsWindows ) {
101
+ $currentUser = [Security.Principal.WindowsPrincipal ]([Security.Principal.WindowsIdentity ]::GetCurrent())
102
+ $isAdminProcess = $currentUser.IsInRole ([Security.Principal.WindowsBuiltInRole ]::Administrator)
103
+ }
104
+ else {
105
+ # Must be Linux or OSX, so use the id util. Root has userid of 0.
106
+ $isAdminProcess = 0 -eq (id - u)
107
+ }
100
108
101
109
$adminHeader = if ($isAdminProcess ) { ' Administrator: ' } else { ' ' }
102
110
@@ -252,14 +260,14 @@ if(!(Test-Path Variable:Global:VcsPromptStatuses)) {
252
260
$s = $global :GitPromptSettings
253
261
254
262
# Override some of the normal colors if the background color is set to the default DarkMagenta.
255
- if ($Host.UI.RawUI.BackgroundColor -eq [ConsoleColor ]::DarkMagenta) {
263
+ if ($Host.UI.RawUI.BackgroundColor -eq [ConsoleColor ]::DarkMagenta) {
256
264
$s.LocalDefaultStatusForegroundColor = $s.LocalDefaultStatusForegroundBrightColor
257
265
$s.LocalWorkingStatusForegroundColor = $s.LocalWorkingStatusForegroundBrightColor
258
266
259
- $s.BeforeIndexForegroundColor = $s.BeforeIndexForegroundBrightColor
260
- $s.IndexForegroundColor = $s.IndexForegroundBrightColor
267
+ $s.BeforeIndexForegroundColor = $s.BeforeIndexForegroundBrightColor
268
+ $s.IndexForegroundColor = $s.IndexForegroundBrightColor
261
269
262
- $s.WorkingForegroundColor = $s.WorkingForegroundBrightColor
270
+ $s.WorkingForegroundColor = $s.WorkingForegroundBrightColor
263
271
}
264
272
265
273
function Global :Write-VcsStatus { $Global :VcsPromptStatuses | foreach { & $_ } }
0 commit comments