Skip to content
This repository was archived by the owner on Feb 16, 2021. It is now read-only.

Commit 5df7c5b

Browse files
hugo-vrijswijkJanJoris
authored andcommitted
Add option to hide username and domain in certain themes
1 parent f607ed1 commit 5df7c5b

8 files changed

+83
-15
lines changed

Helpers/Prompt.Tests.ps1

+48
Original file line numberDiff line numberDiff line change
@@ -110,4 +110,52 @@ Describe "Get-Drive" {
110110
Get-Drive $path | Should Be 'L:'
111111
}
112112
}
113+
}
114+
115+
Describe "Test-NotDefaultUser" {
116+
Context "With default user set" {
117+
BeforeAll { $DefaultUser = 'name' }
118+
It "same username gives 'false'" {
119+
$user = 'name'
120+
Test-NotDefaultUser($user) | Should Be $false
121+
}
122+
It "different username gives 'false'" {
123+
$user = 'differentName'
124+
Test-NotDefaultUser($user) | Should Be $true
125+
}
126+
It "same username and outside VirtualEnv gives 'false'" {
127+
Mock Test-VirtualEnv { return $false }
128+
$user = 'name'
129+
Test-NotDefaultUser($user) | Should Be $false
130+
}
131+
It "same username and inside VirtualEnv same default user gives 'true'" {
132+
Mock Test-VirtualEnv { return $true }
133+
$user = 'name'
134+
Test-NotDefaultUser($user) | Should Be $true
135+
}
136+
It "different username and inside VirtualEnv same default user gives 'true'" {
137+
Mock Test-VirtualEnv { return $true }
138+
$user = 'differentName'
139+
Test-NotDefaultUser($user) | Should Be $true
140+
}
141+
}
142+
Context "With no default user set" {
143+
BeforeAll { $DefaultUser = $null }
144+
It "no username gives 'true'" {
145+
Test-NotDefaultUser | Should Be $true
146+
}
147+
It "different username gives 'true'" {
148+
$user = 'differentName'
149+
Test-NotDefaultUser($user) | Should Be $true
150+
}
151+
It "different username and outside VirtualEnv gives 'true'" {
152+
Mock Test-VirtualEnv { return $false }
153+
$user = 'differentName'
154+
Test-NotDefaultUser($user) | Should Be $true
155+
}
156+
It "no username and inside VirtualEnv gives 'true'" {
157+
Mock Test-VirtualEnv { return $true }
158+
Test-NotDefaultUser($user) | Should Be $true
159+
}
160+
}
113161
}

Helpers/Prompt.ps1

+4
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,10 @@ function Get-VirtualEnvName {
140140
return $virtualEnvName
141141
}
142142

143+
function Test-NotDefaultUser($user) {
144+
return $DefaultUser -eq $null -or $user -ne $DefaultUser -or (Test-VirtualEnv)
145+
}
146+
143147
function Set-CursorForRightBlockWrite {
144148
param(
145149
[int]

README.md

+6
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,12 @@ Also do not forget the Posh-Git settings itself (enable the stash indication for
8181
$GitPromptSettings
8282
```
8383

84+
Hide your `username@domain` when not in a virtual machine for the Agnoster, Fish, Honukai, Paradox and Sorin themes:
85+
86+
```bash
87+
$DefaultUser = 'yourUsernameHere'
88+
```
89+
8490
## Helper functions
8591

8692
`Set-Theme`: set a theme from the Themes directory. If no match is found, it will not be changed. Autocomplete is available to list and complete available themes.

Themes/Agnoster.psm1

+3-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ function Write-Theme {
2525

2626
$user = [Environment]::UserName
2727
$computer = $env:computername
28-
Write-Prompt -Object "$user@$computer " -ForegroundColor $sl.Colors.SessionInfoForegroundColor -BackgroundColor $sl.Colors.SessionInfoBackgroundColor
28+
if (Test-NotDefaultUser($user)) {
29+
Write-Prompt -Object "$user@$computer " -ForegroundColor $sl.Colors.SessionInfoForegroundColor -BackgroundColor $sl.Colors.SessionInfoBackgroundColor
30+
}
2931

3032
if (Test-VirtualEnv) {
3133
Write-Prompt -Object "$($sl.PromptSymbols.SegmentForwardSymbol) " -ForegroundColor $sl.Colors.SessionInfoBackgroundColor -BackgroundColor $sl.Colors.VirtualEnvBackgroundColor

Themes/Fish.psm1

+5-3
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,11 @@ function Write-Theme {
3838
$user = [Environment]::UserName
3939
$computer = $env:computername
4040
$path = Get-FullPath -dir $pwd
41-
Write-Prompt -Object "$user@$computer " -ForegroundColor $sl.Colors.SessionInfoForegroundColor -BackgroundColor $sl.Colors.SessionInfoBackgroundColor
42-
43-
if (Test-VirtualEnv) {
41+
if (Test-NotDefaultUser($user)) {
42+
Write-Prompt -Object "$user@$computer " -ForegroundColor $sl.Colors.SessionInfoForegroundColor -BackgroundColor $sl.Colors.SessionInfoBackgroundColor
43+
}
44+
45+
if (Test-VirtualEnv) {
4446
Write-Prompt -Object "$($sl.PromptSymbols.SegmentForwardSymbol) " -ForegroundColor $sl.Colors.SessionInfoBackgroundColor -BackgroundColor $sl.Colors.VirtualEnvBackgroundColor
4547
Write-Prompt -Object "$($sl.PromptSymbols.VirtualEnvSymbol) $(Get-VirtualEnvName) " -ForegroundColor $sl.Colors.VirtualEnvForegroundColor -BackgroundColor $sl.Colors.VirtualEnvBackgroundColor
4648
Write-Prompt -Object "$($sl.PromptSymbols.SegmentForwardSymbol) " -ForegroundColor $sl.Colors.VirtualEnvBackgroundColor -BackgroundColor $sl.Colors.PromptBackgroundColor

Themes/Honukai.psm1

+10-7
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,16 @@ function Write-Theme {
1212
Write-Prompt -Object $sl.PromptSymbols.StartSymbol -ForegroundColor $sl.Colors.PromptHighlightColor
1313
# write user
1414
$user = [Environment]::UserName
15-
Write-Prompt -Object " $user" -ForegroundColor $sl.Colors.PromptHighlightColor
16-
# write at (devicename)
17-
$device = $env:computername
18-
Write-Prompt -Object " at" -ForegroundColor $sl.Colors.PromptForegroundColor
19-
Write-Prompt -Object " $device" -ForegroundColor $sl.Colors.GitDefaultColor
20-
# write in (folder)
21-
Write-Prompt -Object " in" -ForegroundColor $sl.Colors.PromptForegroundColor
15+
if (Test-NotDefaultUser($user)) {
16+
Write-Prompt -Object " $user" -ForegroundColor $sl.Colors.PromptHighlightColor
17+
# write at (devicename)
18+
$device = $env:computername
19+
Write-Prompt -Object " at" -ForegroundColor $sl.Colors.PromptForegroundColor
20+
Write-Prompt -Object " $device" -ForegroundColor $sl.Colors.GitDefaultColor
21+
# write in for folder
22+
Write-Prompt -Object " in" -ForegroundColor $sl.Colors.PromptForegroundColor
23+
}
24+
# write folder
2225
$prompt = Get-FullPath -dir $pwd
2326
Write-Prompt -Object " $prompt " -ForegroundColor $sl.Colors.AdminIconForegroundColor
2427
# write on (git:branchname status)

Themes/Paradox.psm1

+4-3
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,10 @@ function Write-Theme {
2424
$user = [Environment]::UserName
2525
$computer = $env:computername
2626
$path = Get-FullPath -dir $pwd
27-
28-
Write-Prompt -Object "$user@$computer " -ForegroundColor $sl.Colors.SessionInfoForegroundColor -BackgroundColor $sl.Colors.SessionInfoBackgroundColor
29-
27+
if (Test-NotDefaultUser($user)) {
28+
Write-Prompt -Object "$user@$computer " -ForegroundColor $sl.Colors.SessionInfoForegroundColor -BackgroundColor $sl.Colors.SessionInfoBackgroundColor
29+
}
30+
3031
if (Test-VirtualEnv) {
3132
Write-Prompt -Object "$($sl.PromptSymbols.SegmentForwardSymbol) " -ForegroundColor $sl.Colors.SessionInfoBackgroundColor -BackgroundColor $sl.Colors.VirtualEnvBackgroundColor
3233
Write-Prompt -Object "$($sl.PromptSymbols.VirtualEnvSymbol) $(Get-VirtualEnvName) " -ForegroundColor $sl.Colors.VirtualEnvForegroundColor -BackgroundColor $sl.Colors.VirtualEnvBackgroundColor

Themes/Sorin.psm1

+3-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ function Write-Theme {
1919
}
2020

2121
$user = [Environment]::UserName
22-
Write-Prompt -Object "$user " -ForegroundColor $sl.Colors.PromptForegroundColor
22+
if (Test-NotDefaultUser($user)) {
23+
Write-Prompt -Object "$user " -ForegroundColor $sl.Colors.PromptForegroundColor
24+
}
2325

2426
# Writes the drive portion
2527
Write-Prompt -Object "$(Get-ShortPath -dir $pwd) " -ForegroundColor $sl.Colors.DriveForegroundColor

0 commit comments

Comments
 (0)