前沿拓展:
windows install
精簡版的VB和Office兼容性不好
精簡版的Office和VB兼容性也不好,都容易出問題
用W戰(zhàn)過湖隊損indows insta來自ll clean up清除一下,再用360清理注冊表
在重裝
1 概述
在我的上一篇文章中,我們學(xué)會了通過 Scoop 和 WSL 快速搭建各種開發(fā)環(huán)境,但是有沒有發(fā)現(xiàn)默認(rèn)的 powershell 很丑而且不好用,今天教大家怎樣安裝 Windows Terminal以及美化,Windows Terminal 是 WSL2 的理想配套,它速度快、可配置、外觀漂亮,并且提供了 Windows 和 Linux 開發(fā)的所有優(yōu)點。
不多說,先看下美化后的 Windows Terminal。
2 安裝
以管理員權(quán)限打開 powershell 并運行下面命令:
# 安裝 Windows Terminal 最新版本
scoop install -g extras/windows-terminal
# 安裝 powershell 最新版本, windows 默認(rèn)的 powershell 版本很低
scoop install -g main/pwsh
# 安裝字體
scoop install -g nerd-fonts/Cascadia-Code
# 安裝openssh
scoop install -g main/openssh3 windows-terminal 配置3.1 配置右鍵菜單
新建 windows-terminal.reg 文件,文件內(nèi)容如下:
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOTDirectoryBackgroundshellWindowsTerminal]
@="Windows Terminal Here"
"Icon"="D:\Softwares\Scoop\GlobalApps\apps\windows-terminal\current\WindowsTerminal.exe"
[HKEY_CLASSES_ROOTDirectoryBackgroundshellWindowsTerminalcommand]
@="D:\Softwares\Scoop\GlobalApps\apps\windows-terminal\current\WindowsTerminal.exe"
其中的路徑是安裝 windows-terminal的路徑,配置完成后雙擊運行。
3.2 配置 pwsh
1.右鍵打開 windows-terminal, 選擇設(shè)置。
2.選擇添加新的配置文件。
3.選擇**配置文件。
4.修改配置文件為 pwsh 的配置文件。
5.修改啟動為 pwsh。
6.選擇配色方案。
3.3 全局配置
打開配置文件,進(jìn)行全局配置,全局配置是在 defaults下配置的,list 下是單獨配置每個命令行的,list 下的配置會覆蓋全局配置的,如果在 defaults下已經(jīng)配置了,list 下相同的配置需要刪除,全局配置內(nèi)容如下:
"defaults": {
// 配置背景圖片
"backgroundImage": "D:\SoftwareConfigs\Windows-terminal\background.jpg",
// 配置透明度
"backgroundImageOpacity": 0.1,
// 配置主題
"colorScheme": "One Half Dark",
// 配置字體
"font": {
"face": "Cascadia Mono",
"size": 12
},
// 配置歷史記錄大小
"historySize": 9001,
// 配置啟動時進(jìn)入的目錄,配置為 null時會進(jìn)入右鍵打開時所在的目錄
"startingDirectory": null,
// 選擇文本底色
"selectionBackground": "#EE3A8C"
},4 pwsh 配置4.1 安裝插件
為了讓 pwsh 更好用,我們需要安裝一些 powershell的插件,運行下面命令進(jìn)行安裝:
Set-PSRepository -Name PSGallery -InstallationPolicy Trusted
Set-ExecutionPolicy remotesigned
# PowerShell 的彩色文件列表
Install-Module -AllowClobber Get-ChildItemColor -Scope AllUsers
# 增強(qiáng) git 功能
PowerShellGetInstall-Module -Name posh-git -Scope AllUsers -AllowPrerelease -Force
PowerShellGetInstall-Module posh-sshell -Scope AllUsers
# 美化 powershell
Install-Module -Name oh-my-posh -Scope AllUsers
# git 別名支持
Install-Module -Name git-aliases -Scope AllUsers
# powershell 增強(qiáng)
Install-Module -Name PSReadLine -AllowPrerelease -Scope AllUsers -Force -SkipPublisherCheck
# 系統(tǒng)信息輸出
Install-Module windows-screenfetch -Scope AllUsers -AllowClobber
Install-Module -Name InstallModuleFromGitHub -Scope AllUsers4.2 windows-screenfetch 配置
windows-screenfetch 已經(jīng)不適用于最新版本的 powershell ,所以需要更改下源碼,找到 C:Program FilesPowerShellModuleswindows-screenfetch1.0.2下的 Data.p**1文件,將里面所有內(nèi)容替換為下面內(nèi)容:
Add-Type -AssemblyName System.Windows.Forms
Function Get-SystemSpecifications()
{
$UserInfo = Get-UserInformation;
$OS = Get-OS;
$Kernel = Get-Kernel;
$Uptime = Get-Uptime;
$Motherboard = Get-Mobo;
$Shell = Get-Shell;
$Displays = Get-Displays;
$WM = Get-WM;
$Font = Get-Font;
$CPU = Get-CPU;
$GPU = Get-GPU;
$RAM = Get-RAM;
$Disks = Get-Disks;
[System.Collections.ArrayList] $SystemInfoCollection =
$UserInfo,
$OS,
$Kernel,
$Uptime,
$Motherboard,
$Shell,
$Displays,
$WM,
$Font,
$CPU,
$GPU,
$RAM;
foreach ($Disk in $Disks)
{
[void]$SystemInfoCollection.Add($Disk);
}
return $SystemInfoCollection;
}
Function Get-LineToTitleMappings()
{
$TitleMappings = @{
0 = "";
1 = "OS: ";
2 = "Kernel: ";
3 = "Uptime: ";
4 = "Motherboard: ";
5 = "Shell: ";
6 = "Resolution: ";
7 = "Window Manager: ";
8 = "Font: ";
9 = "CPU: ";
10 = "GPU ";
11 = "RAM: ";
};
return $TitleMappings;
}
Function Get-UserInformation()
{
return $env:USERNAME + "@" + (Get-CimInstance Win32_OperatingSystem).CSName;
}
Function Get-OS()
{
return (Get-CimInstance Win32_OperatingSystem).Caption + " " +
(Get-CimInstance Win32_OperatingSystem).OSArchitecture;
}
Function Get-Kernel()
{
return (Get-CimInstance Win32_OperatingSystem).Version;
}
Function Get-Uptime()
{
$Uptime = (Get-CimInstance Win32_OperatingSystem).LocalDateTime – (Get-CimInstance Win32_OperatingSystem).LastBootUpTime;
$FormattedUptime = $Uptime.Days.ToString() + "d " + $Uptime.Hours.ToString() + "h " + $Uptime.Minutes.ToString() + "m " + $Uptime.Seconds.ToString() + "s ";
return $FormattedUptime;
}
Function Get-Mobo()
{
$Motherboard = Get-CimInstance Win32_BaseBoard | Select-Object Manufacturer, Product;
return $Motherboard.Manufacturer + " " + $Motherboard.Product;
}
Function Get-Shell()
{
return "PowerShell $($PSVersionTable.PSVersion.ToString())";
}
Function Get-Displays()
{
$Displays = New-Object System.Collections.Generic.List[System.Object];
# This gives the available resolutions
$monitors = Get-CimInstance -N "rootwmi" -Class WmiMonitorListedSupportedSourceModes
foreach($monitor in $monitors)
{
# Sort the available modes by display area (width*height)
$sortedResolutions = $monitor.MonitorSourceModes | sort -property {$_.HorizontalActivePixels * $_.VerticalActivePixels}
$maxResolutions = $sortedResolutions | select @{N="MaxRes";E={"$($_.HorizontalActivePixels) x $($_.VerticalActivePixels) "}}
$Displays.Add(($maxResolutions | select -last 1).MaxRes);
}
return $Displays;
}
Function Get-WM()
{
return "DWM";
}
Function Get-Font()
{
return "Segoe UI";
}
Function Get-CPU()
{
return (((Get-CimInstance Win32_Processor).Name) -replace 's+', ' ');
}
Function Get-GPU()
{
return (Get-CimInstance Win32_DisplayConfiguration).DeviceName;
}
Function Get-RAM()
{
$FreeRam = ([math]::Truncate((Get-CimInstance Win32_OperatingSystem).FreePhysicalMemory / 1KB));
$TotalRam = ([math]::Truncate((Get-CimInstance Win32_ComputerSystem).TotalPhysicalMemory / 1MB));
$UsedRam = $TotalRam – $FreeRam;
$FreeRamPercent = ($FreeRam / $TotalRam) * 100;
$FreeRamPercent = "{0:N0}" -f $FreeRamPercent;
$UsedRamPercent = ($UsedRam / $TotalRam) * 100;
$UsedRamPercent = "{0:N0}" -f $UsedRamPercent;
return $UsedRam.ToString() + "MB / " + $TotalRam.ToString() + " MB " + "(" + $UsedRamPercent.ToString() + "%" + ")";
}
Function Get-Disks()
{
$FormattedDisks = New-Object System.Collections.Generic.List[System.Object];
$NumDisks = (Get-CimInstance Win32_LogicalDisk).Count;
if ($NumDisks)
{
for ($i=0; $i -lt ($NumDisks); $i++)
{
$DiskID = (Get-CimInstance Win32_LogicalDisk)[$i].DeviceId;
$FreeDiskSize = (Get-CimInstance Win32_LogicalDisk)[$i].FreeSpace
$FreeDiskSizeGB = $FreeDiskSize / 1073741824;
$FreeDiskSizeGB = "{0:N0}" -f $FreeDiskSizeGB;
$DiskSize = (Get-CimInstance Win32_LogicalDisk)[$i].Size;
$DiskSizeGB = $DiskSize / 1073741824;
$DiskSizeGB = "{0:N0}" -f $DiskSizeGB;
$FreeDiskPercent = ($FreeDiskSizeGB / $DiskSizeGB) * 100;
$FreeDiskPercent = "{0:N0}" -f $FreeDiskPercent;
$UsedDiskSizeGB = $DiskSizeGB – $FreeDiskSizeGB;
$UsedDiskPercent = ($UsedDiskSizeGB / $DiskSizeGB) * 100;
$UsedDiskPercent = "{0:N0}" -f $UsedDiskPercent;
$FormattedDisk = "Disk " + $DiskID.ToString() + " " +
$UsedDiskSizeGB.ToString() + "GB" + " / " + $DiskSizeGB.ToString() + "GB " +
"(" + $UsedDiskPercent.ToString() + "%" + ")";
$FormattedDisks.Add($FormattedDisk);
}
}
else
{
$DiskID = (Get-CimInstance Win32_LogicalDisk).DeviceId;
$FreeDiskSize = (Get-CimInstance Win32_LogicalDisk).FreeSpace
$FreeDiskSizeGB = $FreeDiskSize / 1073741824;
$FreeDiskSizeGB = "{0:N0}" -f $FreeDiskSizeGB;
$DiskSize = (Get-CimInstance Win32_LogicalDisk).Size;
$DiskSizeGB = $DiskSize / 1073741824;
$DiskSizeGB = "{0:N0}" -f $DiskSizeGB;
if ($DiskSize -gt 0)
{
$FreeDiskPercent = ($FreeDiskSizeGB / $DiskSizeGB) * 100;
$FreeDiskPercent = "{0:N0}" -f $FreeDiskPercent;
$UsedDiskSizeGB = $DiskSizeGB – $FreeDiskSizeGB;
$UsedDiskPercent = ($UsedDiskSizeGB / $DiskSizeGB) * 100;
$UsedDiskPercent = "{0:N0}" -f $UsedDiskPercent;
$FormattedDisk = "Disk " + $DiskID.ToString() + " " +
$UsedDiskSizeGB.ToString() + "GB" + " / " + $DiskSizeGB.ToString() + "GB " +
"(" + $UsedDiskPercent.ToString() + "%" + ")";
$FormattedDisks.Add($FormattedDisk);
}
else
{
$FormattedDisk = "Disk " + $DiskID.ToString() + " Empty";
$FormattedDisks.Add($FormattedDisk);
}
}
return $FormattedDisks;
}4.3 啟動時加載插件
為了啟動時加載插件,我們需要創(chuàng)建一個 Microsoft.PowerShell_profile.ps1文件,放到 C:Users自己的用戶名DocumentsPowerShell目錄下,文件內(nèi)容為:
Import-Module windows-screenfetch
Import-Module posh-git
Import-Module posh-sshell
Import-Module oh-my-posh
Import-Module git-aliases -DisableNameChecking
Import-Module PSReadLine
Import-Module InstallModuleFromGitHub
Import-Module Get-ChildItemColor
Screenfetch
Set-PoshPrompt -Theme Material # 設(shè)置主題為 Material
Set-PSReadlineKeyHandler -Key Tab -Function Complete # 設(shè)置 Tab 鍵補(bǔ)全
Set-PSReadLineKeyHandler -Key "Ctrl+d" -Function MenuComplete # 設(shè)置 Ctrl+d 為菜單補(bǔ)全和 Intellisense
Set-PSReadLineKeyHandler -Key "Ctrl+z" -Function Undo # 設(shè)置 Ctrl+z 為撤銷
Set-PSReadLineKeyHandler -Key UpArrow -Function HistorySearchBackward # 設(shè)置向上鍵為后向搜索歷史記錄
Set-PSReadLineKeyHandler -Key DownArrow -Function HistorySearchForward # 設(shè)置向下鍵為前向搜索歷史紀(jì)錄5 小編綜合來說
Windows Terminal 的安裝與美化到這里就已經(jīng)結(jié)束了,其中 pwsh 安裝的一些插件,如果大家想了解其具體用法,可以去官網(wǎng)查看。
拓展知識:
前沿拓展:
windows install
精簡版的VB和Office兼容性不好
精簡版的Office和VB兼容性也不好,都容易出問題
用W戰(zhàn)過湖隊損indows insta來自ll clean up清除一下,再用360清理注冊表
在重裝
1 概述
在我的上一篇文章中,我們學(xué)會了通過 Scoop 和 WSL 快速搭建各種開發(fā)環(huán)境,但是有沒有發(fā)現(xiàn)默認(rèn)的 powershell 很丑而且不好用,今天教大家怎樣安裝 Windows Terminal以及美化,Windows Terminal 是 WSL2 的理想配套,它速度快、可配置、外觀漂亮,并且提供了 Windows 和 Linux 開發(fā)的所有優(yōu)點。
不多說,先看下美化后的 Windows Terminal。
2 安裝
以管理員權(quán)限打開 powershell 并運行下面命令:
# 安裝 Windows Terminal 最新版本
scoop install -g extras/windows-terminal
# 安裝 powershell 最新版本, windows 默認(rèn)的 powershell 版本很低
scoop install -g main/pwsh
# 安裝字體
scoop install -g nerd-fonts/Cascadia-Code
# 安裝openssh
scoop install -g main/openssh3 windows-terminal 配置3.1 配置右鍵菜單
新建 windows-terminal.reg 文件,文件內(nèi)容如下:
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOTDirectoryBackgroundshellWindowsTerminal]
@="Windows Terminal Here"
"Icon"="D:\Softwares\Scoop\GlobalApps\apps\windows-terminal\current\WindowsTerminal.exe"
[HKEY_CLASSES_ROOTDirectoryBackgroundshellWindowsTerminalcommand]
@="D:\Softwares\Scoop\GlobalApps\apps\windows-terminal\current\WindowsTerminal.exe"
其中的路徑是安裝 windows-terminal的路徑,配置完成后雙擊運行。
3.2 配置 pwsh
1.右鍵打開 windows-terminal, 選擇設(shè)置。
2.選擇添加新的配置文件。
3.選擇**配置文件。
4.修改配置文件為 pwsh 的配置文件。
5.修改啟動為 pwsh。
6.選擇配色方案。
3.3 全局配置
打開配置文件,進(jìn)行全局配置,全局配置是在 defaults下配置的,list 下是單獨配置每個命令行的,list 下的配置會覆蓋全局配置的,如果在 defaults下已經(jīng)配置了,list 下相同的配置需要刪除,全局配置內(nèi)容如下:
"defaults": {
// 配置背景圖片
"backgroundImage": "D:\SoftwareConfigs\Windows-terminal\background.jpg",
// 配置透明度
"backgroundImageOpacity": 0.1,
// 配置主題
"colorScheme": "One Half Dark",
// 配置字體
"font": {
"face": "Cascadia Mono",
"size": 12
},
// 配置歷史記錄大小
"historySize": 9001,
// 配置啟動時進(jìn)入的目錄,配置為 null時會進(jìn)入右鍵打開時所在的目錄
"startingDirectory": null,
// 選擇文本底色
"selectionBackground": "#EE3A8C"
},4 pwsh 配置4.1 安裝插件
為了讓 pwsh 更好用,我們需要安裝一些 powershell的插件,運行下面命令進(jìn)行安裝:
Set-PSRepository -Name PSGallery -InstallationPolicy Trusted
Set-ExecutionPolicy remotesigned
# PowerShell 的彩色文件列表
Install-Module -AllowClobber Get-ChildItemColor -Scope AllUsers
# 增強(qiáng) git 功能
PowerShellGetInstall-Module -Name posh-git -Scope AllUsers -AllowPrerelease -Force
PowerShellGetInstall-Module posh-sshell -Scope AllUsers
# 美化 powershell
Install-Module -Name oh-my-posh -Scope AllUsers
# git 別名支持
Install-Module -Name git-aliases -Scope AllUsers
# powershell 增強(qiáng)
Install-Module -Name PSReadLine -AllowPrerelease -Scope AllUsers -Force -SkipPublisherCheck
# 系統(tǒng)信息輸出
Install-Module windows-screenfetch -Scope AllUsers -AllowClobber
Install-Module -Name InstallModuleFromGitHub -Scope AllUsers4.2 windows-screenfetch 配置
windows-screenfetch 已經(jīng)不適用于最新版本的 powershell ,所以需要更改下源碼,找到 C:Program FilesPowerShellModuleswindows-screenfetch1.0.2下的 Data.p**1文件,將里面所有內(nèi)容替換為下面內(nèi)容:
Add-Type -AssemblyName System.Windows.Forms
Function Get-SystemSpecifications()
{
$UserInfo = Get-UserInformation;
$OS = Get-OS;
$Kernel = Get-Kernel;
$Uptime = Get-Uptime;
$Motherboard = Get-Mobo;
$Shell = Get-Shell;
$Displays = Get-Displays;
$WM = Get-WM;
$Font = Get-Font;
$CPU = Get-CPU;
$GPU = Get-GPU;
$RAM = Get-RAM;
$Disks = Get-Disks;
[System.Collections.ArrayList] $SystemInfoCollection =
$UserInfo,
$OS,
$Kernel,
$Uptime,
$Motherboard,
$Shell,
$Displays,
$WM,
$Font,
$CPU,
$GPU,
$RAM;
foreach ($Disk in $Disks)
{
[void]$SystemInfoCollection.Add($Disk);
}
return $SystemInfoCollection;
}
Function Get-LineToTitleMappings()
{
$TitleMappings = @{
0 = "";
1 = "OS: ";
2 = "Kernel: ";
3 = "Uptime: ";
4 = "Motherboard: ";
5 = "Shell: ";
6 = "Resolution: ";
7 = "Window Manager: ";
8 = "Font: ";
9 = "CPU: ";
10 = "GPU ";
11 = "RAM: ";
};
return $TitleMappings;
}
Function Get-UserInformation()
{
return $env:USERNAME + "@" + (Get-CimInstance Win32_OperatingSystem).CSName;
}
Function Get-OS()
{
return (Get-CimInstance Win32_OperatingSystem).Caption + " " +
(Get-CimInstance Win32_OperatingSystem).OSArchitecture;
}
Function Get-Kernel()
{
return (Get-CimInstance Win32_OperatingSystem).Version;
}
Function Get-Uptime()
{
$Uptime = (Get-CimInstance Win32_OperatingSystem).LocalDateTime – (Get-CimInstance Win32_OperatingSystem).LastBootUpTime;
$FormattedUptime = $Uptime.Days.ToString() + "d " + $Uptime.Hours.ToString() + "h " + $Uptime.Minutes.ToString() + "m " + $Uptime.Seconds.ToString() + "s ";
return $FormattedUptime;
}
Function Get-Mobo()
{
$Motherboard = Get-CimInstance Win32_BaseBoard | Select-Object Manufacturer, Product;
return $Motherboard.Manufacturer + " " + $Motherboard.Product;
}
Function Get-Shell()
{
return "PowerShell $($PSVersionTable.PSVersion.ToString())";
}
Function Get-Displays()
{
$Displays = New-Object System.Collections.Generic.List[System.Object];
# This gives the available resolutions
$monitors = Get-CimInstance -N "rootwmi" -Class WmiMonitorListedSupportedSourceModes
foreach($monitor in $monitors)
{
# Sort the available modes by display area (width*height)
$sortedResolutions = $monitor.MonitorSourceModes | sort -property {$_.HorizontalActivePixels * $_.VerticalActivePixels}
$maxResolutions = $sortedResolutions | select @{N="MaxRes";E={"$($_.HorizontalActivePixels) x $($_.VerticalActivePixels) "}}
$Displays.Add(($maxResolutions | select -last 1).MaxRes);
}
return $Displays;
}
Function Get-WM()
{
return "DWM";
}
Function Get-Font()
{
return "Segoe UI";
}
Function Get-CPU()
{
return (((Get-CimInstance Win32_Processor).Name) -replace 's+', ' ');
}
Function Get-GPU()
{
return (Get-CimInstance Win32_DisplayConfiguration).DeviceName;
}
Function Get-RAM()
{
$FreeRam = ([math]::Truncate((Get-CimInstance Win32_OperatingSystem).FreePhysicalMemory / 1KB));
$TotalRam = ([math]::Truncate((Get-CimInstance Win32_ComputerSystem).TotalPhysicalMemory / 1MB));
$UsedRam = $TotalRam – $FreeRam;
$FreeRamPercent = ($FreeRam / $TotalRam) * 100;
$FreeRamPercent = "{0:N0}" -f $FreeRamPercent;
$UsedRamPercent = ($UsedRam / $TotalRam) * 100;
$UsedRamPercent = "{0:N0}" -f $UsedRamPercent;
return $UsedRam.ToString() + "MB / " + $TotalRam.ToString() + " MB " + "(" + $UsedRamPercent.ToString() + "%" + ")";
}
Function Get-Disks()
{
$FormattedDisks = New-Object System.Collections.Generic.List[System.Object];
$NumDisks = (Get-CimInstance Win32_LogicalDisk).Count;
if ($NumDisks)
{
for ($i=0; $i -lt ($NumDisks); $i++)
{
$DiskID = (Get-CimInstance Win32_LogicalDisk)[$i].DeviceId;
$FreeDiskSize = (Get-CimInstance Win32_LogicalDisk)[$i].FreeSpace
$FreeDiskSizeGB = $FreeDiskSize / 1073741824;
$FreeDiskSizeGB = "{0:N0}" -f $FreeDiskSizeGB;
$DiskSize = (Get-CimInstance Win32_LogicalDisk)[$i].Size;
$DiskSizeGB = $DiskSize / 1073741824;
$DiskSizeGB = "{0:N0}" -f $DiskSizeGB;
$FreeDiskPercent = ($FreeDiskSizeGB / $DiskSizeGB) * 100;
$FreeDiskPercent = "{0:N0}" -f $FreeDiskPercent;
$UsedDiskSizeGB = $DiskSizeGB – $FreeDiskSizeGB;
$UsedDiskPercent = ($UsedDiskSizeGB / $DiskSizeGB) * 100;
$UsedDiskPercent = "{0:N0}" -f $UsedDiskPercent;
$FormattedDisk = "Disk " + $DiskID.ToString() + " " +
$UsedDiskSizeGB.ToString() + "GB" + " / " + $DiskSizeGB.ToString() + "GB " +
"(" + $UsedDiskPercent.ToString() + "%" + ")";
$FormattedDisks.Add($FormattedDisk);
}
}
else
{
$DiskID = (Get-CimInstance Win32_LogicalDisk).DeviceId;
$FreeDiskSize = (Get-CimInstance Win32_LogicalDisk).FreeSpace
$FreeDiskSizeGB = $FreeDiskSize / 1073741824;
$FreeDiskSizeGB = "{0:N0}" -f $FreeDiskSizeGB;
$DiskSize = (Get-CimInstance Win32_LogicalDisk).Size;
$DiskSizeGB = $DiskSize / 1073741824;
$DiskSizeGB = "{0:N0}" -f $DiskSizeGB;
if ($DiskSize -gt 0)
{
$FreeDiskPercent = ($FreeDiskSizeGB / $DiskSizeGB) * 100;
$FreeDiskPercent = "{0:N0}" -f $FreeDiskPercent;
$UsedDiskSizeGB = $DiskSizeGB – $FreeDiskSizeGB;
$UsedDiskPercent = ($UsedDiskSizeGB / $DiskSizeGB) * 100;
$UsedDiskPercent = "{0:N0}" -f $UsedDiskPercent;
$FormattedDisk = "Disk " + $DiskID.ToString() + " " +
$UsedDiskSizeGB.ToString() + "GB" + " / " + $DiskSizeGB.ToString() + "GB " +
"(" + $UsedDiskPercent.ToString() + "%" + ")";
$FormattedDisks.Add($FormattedDisk);
}
else
{
$FormattedDisk = "Disk " + $DiskID.ToString() + " Empty";
$FormattedDisks.Add($FormattedDisk);
}
}
return $FormattedDisks;
}4.3 啟動時加載插件
為了啟動時加載插件,我們需要創(chuàng)建一個 Microsoft.PowerShell_profile.ps1文件,放到 C:Users自己的用戶名DocumentsPowerShell目錄下,文件內(nèi)容為:
Import-Module windows-screenfetch
Import-Module posh-git
Import-Module posh-sshell
Import-Module oh-my-posh
Import-Module git-aliases -DisableNameChecking
Import-Module PSReadLine
Import-Module InstallModuleFromGitHub
Import-Module Get-ChildItemColor
Screenfetch
Set-PoshPrompt -Theme Material # 設(shè)置主題為 Material
Set-PSReadlineKeyHandler -Key Tab -Function Complete # 設(shè)置 Tab 鍵補(bǔ)全
Set-PSReadLineKeyHandler -Key "Ctrl+d" -Function MenuComplete # 設(shè)置 Ctrl+d 為菜單補(bǔ)全和 Intellisense
Set-PSReadLineKeyHandler -Key "Ctrl+z" -Function Undo # 設(shè)置 Ctrl+z 為撤銷
Set-PSReadLineKeyHandler -Key UpArrow -Function HistorySearchBackward # 設(shè)置向上鍵為后向搜索歷史記錄
Set-PSReadLineKeyHandler -Key DownArrow -Function HistorySearchForward # 設(shè)置向下鍵為前向搜索歷史紀(jì)錄5 小編綜合來說
Windows Terminal 的安裝與美化到這里就已經(jīng)結(jié)束了,其中 pwsh 安裝的一些插件,如果大家想了解其具體用法,可以去官網(wǎng)查看。
拓展知識:
前沿拓展:
windows install
精簡版的VB和Office兼容性不好
精簡版的Office和VB兼容性也不好,都容易出問題
用W戰(zhàn)過湖隊損indows insta來自ll clean up清除一下,再用360清理注冊表
在重裝
1 概述
在我的上一篇文章中,我們學(xué)會了通過 Scoop 和 WSL 快速搭建各種開發(fā)環(huán)境,但是有沒有發(fā)現(xiàn)默認(rèn)的 powershell 很丑而且不好用,今天教大家怎樣安裝 Windows Terminal以及美化,Windows Terminal 是 WSL2 的理想配套,它速度快、可配置、外觀漂亮,并且提供了 Windows 和 Linux 開發(fā)的所有優(yōu)點。
不多說,先看下美化后的 Windows Terminal。
2 安裝
以管理員權(quán)限打開 powershell 并運行下面命令:
# 安裝 Windows Terminal 最新版本
scoop install -g extras/windows-terminal
# 安裝 powershell 最新版本, windows 默認(rèn)的 powershell 版本很低
scoop install -g main/pwsh
# 安裝字體
scoop install -g nerd-fonts/Cascadia-Code
# 安裝openssh
scoop install -g main/openssh3 windows-terminal 配置3.1 配置右鍵菜單
新建 windows-terminal.reg 文件,文件內(nèi)容如下:
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOTDirectoryBackgroundshellWindowsTerminal]
@="Windows Terminal Here"
"Icon"="D:\Softwares\Scoop\GlobalApps\apps\windows-terminal\current\WindowsTerminal.exe"
[HKEY_CLASSES_ROOTDirectoryBackgroundshellWindowsTerminalcommand]
@="D:\Softwares\Scoop\GlobalApps\apps\windows-terminal\current\WindowsTerminal.exe"
其中的路徑是安裝 windows-terminal的路徑,配置完成后雙擊運行。
3.2 配置 pwsh
1.右鍵打開 windows-terminal, 選擇設(shè)置。
2.選擇添加新的配置文件。
3.選擇**配置文件。
4.修改配置文件為 pwsh 的配置文件。
5.修改啟動為 pwsh。
6.選擇配色方案。
3.3 全局配置
打開配置文件,進(jìn)行全局配置,全局配置是在 defaults下配置的,list 下是單獨配置每個命令行的,list 下的配置會覆蓋全局配置的,如果在 defaults下已經(jīng)配置了,list 下相同的配置需要刪除,全局配置內(nèi)容如下:
"defaults": {
// 配置背景圖片
"backgroundImage": "D:\SoftwareConfigs\Windows-terminal\background.jpg",
// 配置透明度
"backgroundImageOpacity": 0.1,
// 配置主題
"colorScheme": "One Half Dark",
// 配置字體
"font": {
"face": "Cascadia Mono",
"size": 12
},
// 配置歷史記錄大小
"historySize": 9001,
// 配置啟動時進(jìn)入的目錄,配置為 null時會進(jìn)入右鍵打開時所在的目錄
"startingDirectory": null,
// 選擇文本底色
"selectionBackground": "#EE3A8C"
},4 pwsh 配置4.1 安裝插件
為了讓 pwsh 更好用,我們需要安裝一些 powershell的插件,運行下面命令進(jìn)行安裝:
Set-PSRepository -Name PSGallery -InstallationPolicy Trusted
Set-ExecutionPolicy remotesigned
# PowerShell 的彩色文件列表
Install-Module -AllowClobber Get-ChildItemColor -Scope AllUsers
# 增強(qiáng) git 功能
PowerShellGetInstall-Module -Name posh-git -Scope AllUsers -AllowPrerelease -Force
PowerShellGetInstall-Module posh-sshell -Scope AllUsers
# 美化 powershell
Install-Module -Name oh-my-posh -Scope AllUsers
# git 別名支持
Install-Module -Name git-aliases -Scope AllUsers
# powershell 增強(qiáng)
Install-Module -Name PSReadLine -AllowPrerelease -Scope AllUsers -Force -SkipPublisherCheck
# 系統(tǒng)信息輸出
Install-Module windows-screenfetch -Scope AllUsers -AllowClobber
Install-Module -Name InstallModuleFromGitHub -Scope AllUsers4.2 windows-screenfetch 配置
windows-screenfetch 已經(jīng)不適用于最新版本的 powershell ,所以需要更改下源碼,找到 C:Program FilesPowerShellModuleswindows-screenfetch1.0.2下的 Data.p**1文件,將里面所有內(nèi)容替換為下面內(nèi)容:
Add-Type -AssemblyName System.Windows.Forms
Function Get-SystemSpecifications()
{
$UserInfo = Get-UserInformation;
$OS = Get-OS;
$Kernel = Get-Kernel;
$Uptime = Get-Uptime;
$Motherboard = Get-Mobo;
$Shell = Get-Shell;
$Displays = Get-Displays;
$WM = Get-WM;
$Font = Get-Font;
$CPU = Get-CPU;
$GPU = Get-GPU;
$RAM = Get-RAM;
$Disks = Get-Disks;
[System.Collections.ArrayList] $SystemInfoCollection =
$UserInfo,
$OS,
$Kernel,
$Uptime,
$Motherboard,
$Shell,
$Displays,
$WM,
$Font,
$CPU,
$GPU,
$RAM;
foreach ($Disk in $Disks)
{
[void]$SystemInfoCollection.Add($Disk);
}
return $SystemInfoCollection;
}
Function Get-LineToTitleMappings()
{
$TitleMappings = @{
0 = "";
1 = "OS: ";
2 = "Kernel: ";
3 = "Uptime: ";
4 = "Motherboard: ";
5 = "Shell: ";
6 = "Resolution: ";
7 = "Window Manager: ";
8 = "Font: ";
9 = "CPU: ";
10 = "GPU ";
11 = "RAM: ";
};
return $TitleMappings;
}
Function Get-UserInformation()
{
return $env:USERNAME + "@" + (Get-CimInstance Win32_OperatingSystem).CSName;
}
Function Get-OS()
{
return (Get-CimInstance Win32_OperatingSystem).Caption + " " +
(Get-CimInstance Win32_OperatingSystem).OSArchitecture;
}
Function Get-Kernel()
{
return (Get-CimInstance Win32_OperatingSystem).Version;
}
Function Get-Uptime()
{
$Uptime = (Get-CimInstance Win32_OperatingSystem).LocalDateTime – (Get-CimInstance Win32_OperatingSystem).LastBootUpTime;
$FormattedUptime = $Uptime.Days.ToString() + "d " + $Uptime.Hours.ToString() + "h " + $Uptime.Minutes.ToString() + "m " + $Uptime.Seconds.ToString() + "s ";
return $FormattedUptime;
}
Function Get-Mobo()
{
$Motherboard = Get-CimInstance Win32_BaseBoard | Select-Object Manufacturer, Product;
return $Motherboard.Manufacturer + " " + $Motherboard.Product;
}
Function Get-Shell()
{
return "PowerShell $($PSVersionTable.PSVersion.ToString())";
}
Function Get-Displays()
{
$Displays = New-Object System.Collections.Generic.List[System.Object];
# This gives the available resolutions
$monitors = Get-CimInstance -N "rootwmi" -Class WmiMonitorListedSupportedSourceModes
foreach($monitor in $monitors)
{
# Sort the available modes by display area (width*height)
$sortedResolutions = $monitor.MonitorSourceModes | sort -property {$_.HorizontalActivePixels * $_.VerticalActivePixels}
$maxResolutions = $sortedResolutions | select @{N="MaxRes";E={"$($_.HorizontalActivePixels) x $($_.VerticalActivePixels) "}}
$Displays.Add(($maxResolutions | select -last 1).MaxRes);
}
return $Displays;
}
Function Get-WM()
{
return "DWM";
}
Function Get-Font()
{
return "Segoe UI";
}
Function Get-CPU()
{
return (((Get-CimInstance Win32_Processor).Name) -replace 's+', ' ');
}
Function Get-GPU()
{
return (Get-CimInstance Win32_DisplayConfiguration).DeviceName;
}
Function Get-RAM()
{
$FreeRam = ([math]::Truncate((Get-CimInstance Win32_OperatingSystem).FreePhysicalMemory / 1KB));
$TotalRam = ([math]::Truncate((Get-CimInstance Win32_ComputerSystem).TotalPhysicalMemory / 1MB));
$UsedRam = $TotalRam – $FreeRam;
$FreeRamPercent = ($FreeRam / $TotalRam) * 100;
$FreeRamPercent = "{0:N0}" -f $FreeRamPercent;
$UsedRamPercent = ($UsedRam / $TotalRam) * 100;
$UsedRamPercent = "{0:N0}" -f $UsedRamPercent;
return $UsedRam.ToString() + "MB / " + $TotalRam.ToString() + " MB " + "(" + $UsedRamPercent.ToString() + "%" + ")";
}
Function Get-Disks()
{
$FormattedDisks = New-Object System.Collections.Generic.List[System.Object];
$NumDisks = (Get-CimInstance Win32_LogicalDisk).Count;
if ($NumDisks)
{
for ($i=0; $i -lt ($NumDisks); $i++)
{
$DiskID = (Get-CimInstance Win32_LogicalDisk)[$i].DeviceId;
$FreeDiskSize = (Get-CimInstance Win32_LogicalDisk)[$i].FreeSpace
$FreeDiskSizeGB = $FreeDiskSize / 1073741824;
$FreeDiskSizeGB = "{0:N0}" -f $FreeDiskSizeGB;
$DiskSize = (Get-CimInstance Win32_LogicalDisk)[$i].Size;
$DiskSizeGB = $DiskSize / 1073741824;
$DiskSizeGB = "{0:N0}" -f $DiskSizeGB;
$FreeDiskPercent = ($FreeDiskSizeGB / $DiskSizeGB) * 100;
$FreeDiskPercent = "{0:N0}" -f $FreeDiskPercent;
$UsedDiskSizeGB = $DiskSizeGB – $FreeDiskSizeGB;
$UsedDiskPercent = ($UsedDiskSizeGB / $DiskSizeGB) * 100;
$UsedDiskPercent = "{0:N0}" -f $UsedDiskPercent;
$FormattedDisk = "Disk " + $DiskID.ToString() + " " +
$UsedDiskSizeGB.ToString() + "GB" + " / " + $DiskSizeGB.ToString() + "GB " +
"(" + $UsedDiskPercent.ToString() + "%" + ")";
$FormattedDisks.Add($FormattedDisk);
}
}
else
{
$DiskID = (Get-CimInstance Win32_LogicalDisk).DeviceId;
$FreeDiskSize = (Get-CimInstance Win32_LogicalDisk).FreeSpace
$FreeDiskSizeGB = $FreeDiskSize / 1073741824;
$FreeDiskSizeGB = "{0:N0}" -f $FreeDiskSizeGB;
$DiskSize = (Get-CimInstance Win32_LogicalDisk).Size;
$DiskSizeGB = $DiskSize / 1073741824;
$DiskSizeGB = "{0:N0}" -f $DiskSizeGB;
if ($DiskSize -gt 0)
{
$FreeDiskPercent = ($FreeDiskSizeGB / $DiskSizeGB) * 100;
$FreeDiskPercent = "{0:N0}" -f $FreeDiskPercent;
$UsedDiskSizeGB = $DiskSizeGB – $FreeDiskSizeGB;
$UsedDiskPercent = ($UsedDiskSizeGB / $DiskSizeGB) * 100;
$UsedDiskPercent = "{0:N0}" -f $UsedDiskPercent;
$FormattedDisk = "Disk " + $DiskID.ToString() + " " +
$UsedDiskSizeGB.ToString() + "GB" + " / " + $DiskSizeGB.ToString() + "GB " +
"(" + $UsedDiskPercent.ToString() + "%" + ")";
$FormattedDisks.Add($FormattedDisk);
}
else
{
$FormattedDisk = "Disk " + $DiskID.ToString() + " Empty";
$FormattedDisks.Add($FormattedDisk);
}
}
return $FormattedDisks;
}4.3 啟動時加載插件
為了啟動時加載插件,我們需要創(chuàng)建一個 Microsoft.PowerShell_profile.ps1文件,放到 C:Users自己的用戶名DocumentsPowerShell目錄下,文件內(nèi)容為:
Import-Module windows-screenfetch
Import-Module posh-git
Import-Module posh-sshell
Import-Module oh-my-posh
Import-Module git-aliases -DisableNameChecking
Import-Module PSReadLine
Import-Module InstallModuleFromGitHub
Import-Module Get-ChildItemColor
Screenfetch
Set-PoshPrompt -Theme Material # 設(shè)置主題為 Material
Set-PSReadlineKeyHandler -Key Tab -Function Complete # 設(shè)置 Tab 鍵補(bǔ)全
Set-PSReadLineKeyHandler -Key "Ctrl+d" -Function MenuComplete # 設(shè)置 Ctrl+d 為菜單補(bǔ)全和 Intellisense
Set-PSReadLineKeyHandler -Key "Ctrl+z" -Function Undo # 設(shè)置 Ctrl+z 為撤銷
Set-PSReadLineKeyHandler -Key UpArrow -Function HistorySearchBackward # 設(shè)置向上鍵為后向搜索歷史記錄
Set-PSReadLineKeyHandler -Key DownArrow -Function HistorySearchForward # 設(shè)置向下鍵為前向搜索歷史紀(jì)錄5 小編綜合來說
Windows Terminal 的安裝與美化到這里就已經(jīng)結(jié)束了,其中 pwsh 安裝的一些插件,如果大家想了解其具體用法,可以去官網(wǎng)查看。
拓展知識:
前沿拓展:
windows install
精簡版的VB和Office兼容性不好
精簡版的Office和VB兼容性也不好,都容易出問題
用W戰(zhàn)過湖隊損indows insta來自ll clean up清除一下,再用360清理注冊表
在重裝
1 概述
在我的上一篇文章中,我們學(xué)會了通過 Scoop 和 WSL 快速搭建各種開發(fā)環(huán)境,但是有沒有發(fā)現(xiàn)默認(rèn)的 powershell 很丑而且不好用,今天教大家怎樣安裝 Windows Terminal以及美化,Windows Terminal 是 WSL2 的理想配套,它速度快、可配置、外觀漂亮,并且提供了 Windows 和 Linux 開發(fā)的所有優(yōu)點。
不多說,先看下美化后的 Windows Terminal。
2 安裝
以管理員權(quán)限打開 powershell 并運行下面命令:
# 安裝 Windows Terminal 最新版本
scoop install -g extras/windows-terminal
# 安裝 powershell 最新版本, windows 默認(rèn)的 powershell 版本很低
scoop install -g main/pwsh
# 安裝字體
scoop install -g nerd-fonts/Cascadia-Code
# 安裝openssh
scoop install -g main/openssh3 windows-terminal 配置3.1 配置右鍵菜單
新建 windows-terminal.reg 文件,文件內(nèi)容如下:
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOTDirectoryBackgroundshellWindowsTerminal]
@="Windows Terminal Here"
"Icon"="D:\Softwares\Scoop\GlobalApps\apps\windows-terminal\current\WindowsTerminal.exe"
[HKEY_CLASSES_ROOTDirectoryBackgroundshellWindowsTerminalcommand]
@="D:\Softwares\Scoop\GlobalApps\apps\windows-terminal\current\WindowsTerminal.exe"
其中的路徑是安裝 windows-terminal的路徑,配置完成后雙擊運行。
3.2 配置 pwsh
1.右鍵打開 windows-terminal, 選擇設(shè)置。
2.選擇添加新的配置文件。
3.選擇**配置文件。
4.修改配置文件為 pwsh 的配置文件。
5.修改啟動為 pwsh。
6.選擇配色方案。
3.3 全局配置
打開配置文件,進(jìn)行全局配置,全局配置是在 defaults下配置的,list 下是單獨配置每個命令行的,list 下的配置會覆蓋全局配置的,如果在 defaults下已經(jīng)配置了,list 下相同的配置需要刪除,全局配置內(nèi)容如下:
"defaults": {
// 配置背景圖片
"backgroundImage": "D:\SoftwareConfigs\Windows-terminal\background.jpg",
// 配置透明度
"backgroundImageOpacity": 0.1,
// 配置主題
"colorScheme": "One Half Dark",
// 配置字體
"font": {
"face": "Cascadia Mono",
"size": 12
},
// 配置歷史記錄大小
"historySize": 9001,
// 配置啟動時進(jìn)入的目錄,配置為 null時會進(jìn)入右鍵打開時所在的目錄
"startingDirectory": null,
// 選擇文本底色
"selectionBackground": "#EE3A8C"
},4 pwsh 配置4.1 安裝插件
為了讓 pwsh 更好用,我們需要安裝一些 powershell的插件,運行下面命令進(jìn)行安裝:
Set-PSRepository -Name PSGallery -InstallationPolicy Trusted
Set-ExecutionPolicy remotesigned
# PowerShell 的彩色文件列表
Install-Module -AllowClobber Get-ChildItemColor -Scope AllUsers
# 增強(qiáng) git 功能
PowerShellGetInstall-Module -Name posh-git -Scope AllUsers -AllowPrerelease -Force
PowerShellGetInstall-Module posh-sshell -Scope AllUsers
# 美化 powershell
Install-Module -Name oh-my-posh -Scope AllUsers
# git 別名支持
Install-Module -Name git-aliases -Scope AllUsers
# powershell 增強(qiáng)
Install-Module -Name PSReadLine -AllowPrerelease -Scope AllUsers -Force -SkipPublisherCheck
# 系統(tǒng)信息輸出
Install-Module windows-screenfetch -Scope AllUsers -AllowClobber
Install-Module -Name InstallModuleFromGitHub -Scope AllUsers4.2 windows-screenfetch 配置
windows-screenfetch 已經(jīng)不適用于最新版本的 powershell ,所以需要更改下源碼,找到 C:Program FilesPowerShellModuleswindows-screenfetch1.0.2下的 Data.p**1文件,將里面所有內(nèi)容替換為下面內(nèi)容:
Add-Type -AssemblyName System.Windows.Forms
Function Get-SystemSpecifications()
{
$UserInfo = Get-UserInformation;
$OS = Get-OS;
$Kernel = Get-Kernel;
$Uptime = Get-Uptime;
$Motherboard = Get-Mobo;
$Shell = Get-Shell;
$Displays = Get-Displays;
$WM = Get-WM;
$Font = Get-Font;
$CPU = Get-CPU;
$GPU = Get-GPU;
$RAM = Get-RAM;
$Disks = Get-Disks;
[System.Collections.ArrayList] $SystemInfoCollection =
$UserInfo,
$OS,
$Kernel,
$Uptime,
$Motherboard,
$Shell,
$Displays,
$WM,
$Font,
$CPU,
$GPU,
$RAM;
foreach ($Disk in $Disks)
{
[void]$SystemInfoCollection.Add($Disk);
}
return $SystemInfoCollection;
}
Function Get-LineToTitleMappings()
{
$TitleMappings = @{
0 = "";
1 = "OS: ";
2 = "Kernel: ";
3 = "Uptime: ";
4 = "Motherboard: ";
5 = "Shell: ";
6 = "Resolution: ";
7 = "Window Manager: ";
8 = "Font: ";
9 = "CPU: ";
10 = "GPU ";
11 = "RAM: ";
};
return $TitleMappings;
}
Function Get-UserInformation()
{
return $env:USERNAME + "@" + (Get-CimInstance Win32_OperatingSystem).CSName;
}
Function Get-OS()
{
return (Get-CimInstance Win32_OperatingSystem).Caption + " " +
(Get-CimInstance Win32_OperatingSystem).OSArchitecture;
}
Function Get-Kernel()
{
return (Get-CimInstance Win32_OperatingSystem).Version;
}
Function Get-Uptime()
{
$Uptime = (Get-CimInstance Win32_OperatingSystem).LocalDateTime – (Get-CimInstance Win32_OperatingSystem).LastBootUpTime;
$FormattedUptime = $Uptime.Days.ToString() + "d " + $Uptime.Hours.ToString() + "h " + $Uptime.Minutes.ToString() + "m " + $Uptime.Seconds.ToString() + "s ";
return $FormattedUptime;
}
Function Get-Mobo()
{
$Motherboard = Get-CimInstance Win32_BaseBoard | Select-Object Manufacturer, Product;
return $Motherboard.Manufacturer + " " + $Motherboard.Product;
}
Function Get-Shell()
{
return "PowerShell $($PSVersionTable.PSVersion.ToString())";
}
Function Get-Displays()
{
$Displays = New-Object System.Collections.Generic.List[System.Object];
# This gives the available resolutions
$monitors = Get-CimInstance -N "rootwmi" -Class WmiMonitorListedSupportedSourceModes
foreach($monitor in $monitors)
{
# Sort the available modes by display area (width*height)
$sortedResolutions = $monitor.MonitorSourceModes | sort -property {$_.HorizontalActivePixels * $_.VerticalActivePixels}
$maxResolutions = $sortedResolutions | select @{N="MaxRes";E={"$($_.HorizontalActivePixels) x $($_.VerticalActivePixels) "}}
$Displays.Add(($maxResolutions | select -last 1).MaxRes);
}
return $Displays;
}
Function Get-WM()
{
return "DWM";
}
Function Get-Font()
{
return "Segoe UI";
}
Function Get-CPU()
{
return (((Get-CimInstance Win32_Processor).Name) -replace 's+', ' ');
}
Function Get-GPU()
{
return (Get-CimInstance Win32_DisplayConfiguration).DeviceName;
}
Function Get-RAM()
{
$FreeRam = ([math]::Truncate((Get-CimInstance Win32_OperatingSystem).FreePhysicalMemory / 1KB));
$TotalRam = ([math]::Truncate((Get-CimInstance Win32_ComputerSystem).TotalPhysicalMemory / 1MB));
$UsedRam = $TotalRam – $FreeRam;
$FreeRamPercent = ($FreeRam / $TotalRam) * 100;
$FreeRamPercent = "{0:N0}" -f $FreeRamPercent;
$UsedRamPercent = ($UsedRam / $TotalRam) * 100;
$UsedRamPercent = "{0:N0}" -f $UsedRamPercent;
return $UsedRam.ToString() + "MB / " + $TotalRam.ToString() + " MB " + "(" + $UsedRamPercent.ToString() + "%" + ")";
}
Function Get-Disks()
{
$FormattedDisks = New-Object System.Collections.Generic.List[System.Object];
$NumDisks = (Get-CimInstance Win32_LogicalDisk).Count;
if ($NumDisks)
{
for ($i=0; $i -lt ($NumDisks); $i++)
{
$DiskID = (Get-CimInstance Win32_LogicalDisk)[$i].DeviceId;
$FreeDiskSize = (Get-CimInstance Win32_LogicalDisk)[$i].FreeSpace
$FreeDiskSizeGB = $FreeDiskSize / 1073741824;
$FreeDiskSizeGB = "{0:N0}" -f $FreeDiskSizeGB;
$DiskSize = (Get-CimInstance Win32_LogicalDisk)[$i].Size;
$DiskSizeGB = $DiskSize / 1073741824;
$DiskSizeGB = "{0:N0}" -f $DiskSizeGB;
$FreeDiskPercent = ($FreeDiskSizeGB / $DiskSizeGB) * 100;
$FreeDiskPercent = "{0:N0}" -f $FreeDiskPercent;
$UsedDiskSizeGB = $DiskSizeGB – $FreeDiskSizeGB;
$UsedDiskPercent = ($UsedDiskSizeGB / $DiskSizeGB) * 100;
$UsedDiskPercent = "{0:N0}" -f $UsedDiskPercent;
$FormattedDisk = "Disk " + $DiskID.ToString() + " " +
$UsedDiskSizeGB.ToString() + "GB" + " / " + $DiskSizeGB.ToString() + "GB " +
"(" + $UsedDiskPercent.ToString() + "%" + ")";
$FormattedDisks.Add($FormattedDisk);
}
}
else
{
$DiskID = (Get-CimInstance Win32_LogicalDisk).DeviceId;
$FreeDiskSize = (Get-CimInstance Win32_LogicalDisk).FreeSpace
$FreeDiskSizeGB = $FreeDiskSize / 1073741824;
$FreeDiskSizeGB = "{0:N0}" -f $FreeDiskSizeGB;
$DiskSize = (Get-CimInstance Win32_LogicalDisk).Size;
$DiskSizeGB = $DiskSize / 1073741824;
$DiskSizeGB = "{0:N0}" -f $DiskSizeGB;
if ($DiskSize -gt 0)
{
$FreeDiskPercent = ($FreeDiskSizeGB / $DiskSizeGB) * 100;
$FreeDiskPercent = "{0:N0}" -f $FreeDiskPercent;
$UsedDiskSizeGB = $DiskSizeGB – $FreeDiskSizeGB;
$UsedDiskPercent = ($UsedDiskSizeGB / $DiskSizeGB) * 100;
$UsedDiskPercent = "{0:N0}" -f $UsedDiskPercent;
$FormattedDisk = "Disk " + $DiskID.ToString() + " " +
$UsedDiskSizeGB.ToString() + "GB" + " / " + $DiskSizeGB.ToString() + "GB " +
"(" + $UsedDiskPercent.ToString() + "%" + ")";
$FormattedDisks.Add($FormattedDisk);
}
else
{
$FormattedDisk = "Disk " + $DiskID.ToString() + " Empty";
$FormattedDisks.Add($FormattedDisk);
}
}
return $FormattedDisks;
}4.3 啟動時加載插件
為了啟動時加載插件,我們需要創(chuàng)建一個 Microsoft.PowerShell_profile.ps1文件,放到 C:Users自己的用戶名DocumentsPowerShell目錄下,文件內(nèi)容為:
Import-Module windows-screenfetch
Import-Module posh-git
Import-Module posh-sshell
Import-Module oh-my-posh
Import-Module git-aliases -DisableNameChecking
Import-Module PSReadLine
Import-Module InstallModuleFromGitHub
Import-Module Get-ChildItemColor
Screenfetch
Set-PoshPrompt -Theme Material # 設(shè)置主題為 Material
Set-PSReadlineKeyHandler -Key Tab -Function Complete # 設(shè)置 Tab 鍵補(bǔ)全
Set-PSReadLineKeyHandler -Key "Ctrl+d" -Function MenuComplete # 設(shè)置 Ctrl+d 為菜單補(bǔ)全和 Intellisense
Set-PSReadLineKeyHandler -Key "Ctrl+z" -Function Undo # 設(shè)置 Ctrl+z 為撤銷
Set-PSReadLineKeyHandler -Key UpArrow -Function HistorySearchBackward # 設(shè)置向上鍵為后向搜索歷史記錄
Set-PSReadLineKeyHandler -Key DownArrow -Function HistorySearchForward # 設(shè)置向下鍵為前向搜索歷史紀(jì)錄5 小編綜合來說
Windows Terminal 的安裝與美化到這里就已經(jīng)結(jié)束了,其中 pwsh 安裝的一些插件,如果大家想了解其具體用法,可以去官網(wǎng)查看。
拓展知識:
原創(chuàng)文章,作者:九賢生活小編,如若轉(zhuǎn)載,請注明出處:http://xiesong.cn/16007.html