Files
artif/windows/winfetch.ps1
2026-02-03 23:54:43 +01:00

162 lines
7.2 KiB
PowerShell

# winfetch.ps1
# Windows system information display with ASCII art (inspired by fastfetch/neofetch)
param(
[ValidateSet("11", "small", "classic")]
[string]$Logo = "11"
)
# Color definitions using ANSI escape codes
$colors = @{
Reset = "`e[0m"
Cyan = "`e[96m"
Blue = "`e[94m"
Green = "`e[92m"
Yellow = "`e[93m"
Red = "`e[91m"
Magenta = "`e[95m"
White = "`e[97m"
Gray = "`e[90m"
BrightBlue = "`e[1;94m"
BrightCyan = "`e[1;96m"
BrightGreen = "`e[1;92m"
BrightYellow = "`e[1;93m"
}
# Windows 11 logo colors (Blue, Cyan, Green, Yellow)
$logo11 = @(
"$($colors.Blue)///////////////// $($colors.BrightCyan)/////////////////",
"$($colors.Blue)///////////////// $($colors.BrightCyan)/////////////////",
"$($colors.Blue)///////////////// $($colors.BrightCyan)/////////////////",
"$($colors.Blue)///////////////// $($colors.BrightCyan)/////////////////",
"$($colors.Blue)///////////////// $($colors.BrightCyan)/////////////////",
"$($colors.Blue)///////////////// $($colors.BrightCyan)/////////////////",
"$($colors.Blue)///////////////// $($colors.BrightCyan)/////////////////",
"$($colors.Blue)///////////////// $($colors.BrightCyan)/////////////////",
"",
"$($colors.BrightGreen)///////////////// $($colors.BrightYellow)/////////////////",
"$($colors.BrightGreen)///////////////// $($colors.BrightYellow)/////////////////",
"$($colors.BrightGreen)///////////////// $($colors.BrightYellow)/////////////////",
"$($colors.BrightGreen)///////////////// $($colors.BrightYellow)/////////////////",
"$($colors.BrightGreen)///////////////// $($colors.BrightYellow)/////////////////",
"$($colors.BrightGreen)///////////////// $($colors.BrightYellow)/////////////////",
"$($colors.BrightGreen)///////////////// $($colors.BrightYellow)/////////////////",
"$($colors.BrightGreen)///////////////// $($colors.BrightYellow)/////////////////"
)
$logoSmall = @(
"$($colors.Blue)lllllll $($colors.BrightCyan)lllllll",
"$($colors.Blue)lllllll $($colors.BrightCyan)lllllll",
"$($colors.Blue)lllllll $($colors.BrightCyan)lllllll",
" ", # Empty line with proper width (16 chars)
"$($colors.BrightGreen)lllllll $($colors.BrightYellow)lllllll",
"$($colors.BrightGreen)lllllll $($colors.BrightYellow)lllllll",
"$($colors.BrightGreen)lllllll $($colors.BrightYellow)lllllll",
" " # Empty line with proper width (16 chars)
)
# Select logo
$asciiLogo = switch ($Logo) {
"small" { $logoSmall }
default { $logo11 }
}
# Collect system information
$computerSystem = Get-CimInstance Win32_ComputerSystem
$os = Get-CimInstance Win32_OperatingSystem
$cpu = Get-CimInstance Win32_Processor | Select-Object -First 1
# Get GPU - prefer discrete GPU over integrated
$gpuList = Get-CimInstance Win32_VideoController | Where-Object { $_.Status -eq 'OK' -or $_.Availability -eq 3 }
$gpu = $gpuList | Where-Object {
$_.Name -match 'NVIDIA|AMD|Radeon|GeForce|RTX|GTX|RX\s*\d'
} | Select-Object -First 1
if (-not $gpu) {
$gpu = $gpuList | Select-Object -First 1
}
$disk = Get-PSDrive -PSProvider FileSystem | Where-Object { $_.Name -eq 'C' }
# Calculate uptime
$uptime = (Get-Date) - $os.LastBootUpTime
$uptimeStr = if ($uptime.Days -gt 0) {
"$($uptime.Days)d $($uptime.Hours)h $($uptime.Minutes)m"
} else {
"$($uptime.Hours)h $($uptime.Minutes)m"
}
# Calculate memory usage
$totalMemGB = [math]::Round($computerSystem.TotalPhysicalMemory / 1GB, 2)
$usedMemGB = [math]::Round(($computerSystem.TotalPhysicalMemory - $os.FreePhysicalMemory * 1KB) / 1GB, 2)
# Calculate disk usage
$totalDiskGB = [math]::Round(($disk.Used + $disk.Free) / 1GB, 2)
$usedDiskGB = [math]::Round($disk.Used / 1GB, 2)
# Get display resolution
$resolution = "N/A"
try {
Add-Type -AssemblyName System.Windows.Forms
$screen = [System.Windows.Forms.Screen]::PrimaryScreen
$resolution = "$($screen.Bounds.Width)x$($screen.Bounds.Height)"
} catch {
# Fallback if GUI not available
if ($gpu.CurrentHorizontalResolution -and $gpu.CurrentVerticalResolution) {
$resolution = "$($gpu.CurrentHorizontalResolution)x$($gpu.CurrentVerticalResolution)"
}
}
# Build info array
if ($Logo -eq "small") {
$info = @(
"$($colors.Cyan)$env:USERNAME$($colors.White)@$($colors.Cyan)$env:COMPUTERNAME",
"$($colors.Gray)$("-" * ($env:USERNAME.Length + $env:COMPUTERNAME.Length + 1))",
"$($colors.BrightBlue)OS$($colors.Reset): $($os.Caption)",
"$($colors.BrightBlue)Uptime$($colors.Reset): $uptimeStr",
"$($colors.BrightBlue)CPU$($colors.Reset): $($cpu.Name.Trim())",
"$($colors.BrightBlue)Memory$($colors.Reset): ${usedMemGB}GB / ${totalMemGB}GB",
"",
(($colors.Keys | Where-Object { $_ -ne 'Reset' -and $_ -ne 'Gray' -and $_ -ne 'White' } | Sort-Object | ForEach-Object { "$($colors[$_])███" }) -join '') + $colors.Reset
)
} else {
$info = @(
"$($colors.Cyan)$env:USERNAME$($colors.White)@$($colors.Cyan)$env:COMPUTERNAME",
"$($colors.Gray)$("-" * ($env:USERNAME.Length + $env:COMPUTERNAME.Length + 1))",
"$($colors.BrightBlue)OS$($colors.Reset): $($os.Caption) [$($os.OSArchitecture)]",
"$($colors.BrightBlue)Host$($colors.Reset): $($computerSystem.Manufacturer) $($computerSystem.Model)",
"$($colors.BrightBlue)Kernel$($colors.Reset): $($os.Version)",
"$($colors.BrightBlue)Uptime$($colors.Reset): $uptimeStr",
"$($colors.BrightBlue)Shell$($colors.Reset): PowerShell $($PSVersionTable.PSVersion)",
"$($colors.BrightBlue)Resolution$($colors.Reset): $resolution",
"$($colors.BrightBlue)Terminal$($colors.Reset): $env:TERM_PROGRAM $(if ($env:WT_SESSION) { "Windows Terminal" } else { "Console" })",
"$($colors.BrightBlue)CPU$($colors.Reset): $($cpu.Name.Trim())",
"$($colors.BrightBlue)GPU$($colors.Reset): $($gpu.Name)",
"$($colors.BrightBlue)Memory$($colors.Reset): ${usedMemGB}GB / ${totalMemGB}GB",
"$($colors.BrightBlue)Disk (C:)$($colors.Reset): ${usedDiskGB}GB / ${totalDiskGB}GB",
"",
(($colors.Keys | Where-Object { $_ -ne 'Reset' -and $_ -ne 'Gray' -and $_ -ne 'White' } | Sort-Object | ForEach-Object { "$($colors[$_])███" }) -join '') + $colors.Reset
)
}
# Display
$maxLines = [Math]::Max($asciiLogo.Count, $info.Count)
# Calculate logo width dynamically
$logoWidth = if ($Logo -eq "small") { 16 } else { 38 }
for ($i = 0; $i -lt $maxLines; $i++) {
$logoLine = if ($i -lt $asciiLogo.Count) { $asciiLogo[$i] } else { "" }
$infoLine = if ($i -lt $info.Count) { $info[$i] } else { "" }
# Pad logo to align info
if ($logoLine) {
$logoStripped = $logoLine -replace '\e\[[0-9;]*m', '' # Remove ANSI codes for length calc
$paddingNeeded = $logoWidth - $logoStripped.Length
if ($paddingNeeded -lt 2) { $paddingNeeded = 2 } # Minimum spacing
Write-Host "$logoLine$(' ' * $paddingNeeded)$infoLine"
} else {
# Empty logo line, just use full logo width for spacing
Write-Host "$(' ' * $logoWidth)$infoLine"
}
}
Write-Host $colors.Reset