-
Notifications
You must be signed in to change notification settings - Fork 32
Expand file tree
/
Copy pathShow-Status.ps1
More file actions
186 lines (175 loc) · 7.68 KB
/
Show-Status.ps1
File metadata and controls
186 lines (175 loc) · 7.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
<#
.SYNOPSIS
Displays requested system status values using powerline font characters.
.LINK
https://www.nerdfonts.com/cheat-sheet
.LINK
Get-Unicode.ps1
.FUNCTIONALITY
System and updates
.EXAMPLE
Show-Status.ps1 UserName HomeDirectory -Separator ' * '
( MyUserName * C:\Users\MyUserName )
(but using powerline graphics)
#>
#Requires -Version 3
[CmdletBinding()][OutputType([void])] Param(
# The format to serialize the date as.
[Parameter(Position=0,Mandatory=$true,ValueFromRemainingArguments=$true)]
[ValidateSet('AdminIndicator','ComputerName','DotNetVersion','DriveUsage','ExplorerUser','GitUser','HomeDirectory',
'OSVersion','PowerShellCommand','PowerShellVersion','Updates','Uptime','UserName')]
[string[]] $Status,
# The separator to use between formatted dates.
[string] $Separator = " $(Get-Unicode.ps1 0x2022) ",
# The foreground console color to use.
[consolecolor] $ForegroundColor = $host.UI.RawUI.BackgroundColor,
# The background console color to use.
[consolecolor] $BackgroundColor = $host.UI.RawUI.ForegroundColor,
# Forces rerunning the command to update the cache.
[switch] $Force
)
Begin
{
Import-CharConstants.ps1 -Alias @{
USER = 'BUST IN SILHOUETTE'
HOUSE = 'HOUSE BUILDING'
COMPUTER = 'PERSONAL COMPUTER'
REDCIRCLE = 'LARGE RED CIRCLE'
BLUECIRCLE = 'LARGE BLUE CIRCLE'
POWER = 'POWER SYMBOL'
HARDDISK = 'HARD DISK'
OVERLAP = 'OVERLAP'
REDX = 'CROSS MARK'
OK = 'SQUARED OK'
WAIT = 'HOURGLASS WITH FLOWING SAND'
'UP!' = 'SQUARED UP WITH EXCLAMATION MARK'
} -AsEmoji
if(Test-WindowsTerminal.ps1)
{
Set-Variable -Name LEFTEND -Value (Get-Unicode.ps1 0xE0B6) -Scope Script -Option Constant -EA Ignore `
-Description 'nf-ple-left_half_circle_thick (wt)'
Set-Variable -Name RIGHTEND -Value (Get-Unicode.ps1 0xE0B4) -Scope Script -Option Constant -EA Ignore `
-Description 'nf-ple-right_half_circle_thick (wt)'
Set-Variable -Name DOTNET -Value (Get-Unicode.ps1 0xE77F) -Scope Script -Option Constant -EA Ignore `
-Description 'nf-dev-dotnet (wt)'
Set-Variable -Name GIT -Value (Get-Unicode.ps1 0xF1D2) -Scope Script -Option Constant -EA Ignore `
-Description 'nf-fa-git_square (wt)'
Set-Variable -Name WINDOWS -Value (Get-Unicode.ps1 0xF17A) -Scope Script -Option Constant -EA Ignore `
-Description 'nf-fa-windows (wt)'
Set-Variable -Name LINUX -Value (Get-Unicode.ps1 0xF17C) -Scope Script -Option Constant -EA Ignore `
-Description 'nf-fa-linux (wt)'
Set-Variable -Name MAC -Value (Get-Unicode.ps1 0xF179) -Scope Script -Option Constant -EA Ignore `
-Description 'nf-fa-apple (wt)'
Set-Variable -Name POWERSHELL -Value (Get-Unicode.ps1 0xE86C) -Scope Script -Option Constant -EA Ignore `
-Description 'nf-dev-powershell (wt)'
}
else
{
Import-CharConstants.ps1 -Alias @{
LEFTEND = 'BLACK MEDIUM LEFT-POINTING TRIANGLE'
RIGHTEND = 'BLACK MEDIUM RIGHT-POINTING TRIANGLE'
DOTNET = 'SINE WAVE'
GIT = 'CIRCLED LATIN SMALL LETTER G'
WINDOWS = 'WINDOW'
LINUX = 'PENGUIN'
MAC = 'RED APPLE'
POWERSHELL = 'SUPERHERO'
} -AsEmoji
}
function Get-WinGetTest
{
if(Get-Module Microsoft.WinGet.Client -ListAvailable)
{{
if(Get-WinGetPackage |
Where-Object IsUpdateAvailable |
Select-Object -First 1) {'winget'}
}}
elseif(Get-Command winget -CommandType Application -ErrorAction Ignore)
{{
if(winget list --upgrade-available --disable-interactivity |
Select-String '^\d+ upgrades? available.$' |
Select-Object -First 1) {'winget'}
}}
else
{{$null}}
}
function Get-ChocoTest
{{
if(Get-Command choco -CommandType Application -ErrorAction Ignore)
{
if(choco outdated -r |Select-Object -First 1) {'choco'}
}
}}
function Get-NpmTest
{{
if(Get-Command npm -CommandType Application -ErrorAction Ignore)
{
if(npm outdated -g -parseable |Select-Object -First 1) {'npm'}
}
}}
function Get-PSModulesTest
{{
if(Get-OutdatedModules.ps1 |Select-Object -First 1) {'psmodules'}
}}
filter Format-Status
{
[CmdletBinding()][OutputType([string])] Param(
[Parameter(ValueFromPipeline=$true)][string] $Status
)
switch($Status)
{
AdminIndicator { (Test-Administrator.ps1) ? $REDCIRCLE : $BLUECIRCLE }
ComputerName {"$COMPUTER $([Environment]::MachineName)"}
DotNetVersion {"$DOTNET .NET $([Environment]::Version)"}
DriveUsage
{
$HARDDISK + ' ' + ((Get-PSDrive -PSProvider FileSystem |Where-Object {$null -ne $_.Free} |
ForEach-Object {"$(Get-Unicode.ps1 (0x1F311 + [math]::Round((5*$_.Used)/($_.Used+$_.Free)) ))$($_.Name)"}) -join ' ')
}
ExplorerUser
{
$euser = New-Object Management.ManagementObjectSearcher `
"select * from Win32_Process where ProcessID = $((Get-Process explorer)[0].Id)" |
ForEach-Object {$_.Get()} |
ForEach-Object {$_.GetOwner()} |
Select-Object -ExpandProperty User
"$OVERLAP $euser"
}
GitUser {(git config user.name) ?
"$GIT $(git config user.name) <$(git config user.email)>" :
"$GIT $REDX"}
HomeDirectory {"$HOUSE $HOME"}
OSVersion
{
if($IsWindows) {"$WINDOWS $([Environment]::OSVersion.VersionString)"}
elseif($IsLinux) {"$LINUX $([Environment]::OSVersion.VersionString) $($PSVersionTable.OS)"}
elseif($IsMacOS) {"$MAC $([Environment]::OSVersion.VersionString) $($PSVersionTable.OS)"}
}
PowerShellCommand {"$POWERSHELL $([Environment]::ProcessPath) $([Environment]::CommandLine)"}
PowerShellVersion {"$POWERSHELL PS $($PSVersionTable.PSVersion) $($PSVersionTable.PSEdition)"}
Updates
{
$updates = @(
(Invoke-CachedCommand.ps1 (Get-ChocoTest) -ExpiresAfter 20:00 -Force:$Force)
(Invoke-CachedCommand.ps1 (Get-WingetTest) -ExpiresAfter 20:00 -Force:$Force)
(Invoke-CachedCommand.ps1 (Get-NpmTest) -ExpiresAfter 20:00 -Force:$Force)
(Invoke-CachedCommand.ps1 (Get-PSModulesTest) -ExpiresAfter 20:00 -Force:$Force)
) |Where-Object {$_}
$updates ? "${UP!} $updates" : $OK
}
Uptime {"$POWER$(Get-Uptime)"}
UserName {"$USER $env:USERNAME"}
default {$_}
}
}
}
Process
{
Write-Info.ps1 $LEFTEND -ForegroundColor $BackgroundColor -NoNewLine
Write-Info.ps1 " $WAIT " -ForegroundColor $ForegroundColor -BackgroundColor $BackgroundColor -NoNewline
Write-Info.ps1 "$RIGHTEND`r$LEFTEND" -ForegroundColor $BackgroundColor -NoNewLine
Write-Info.ps1 (($Status |Format-Status) -join $Separator) `
-ForegroundColor $ForegroundColor -BackgroundColor $BackgroundColor -NoNewline
Write-Info.ps1 ' ' -ForegroundColor $ForegroundColor -BackgroundColor $BackgroundColor -NoNewline
Write-Info.ps1 $RIGHTEND -ForegroundColor $BackgroundColor
}