概览
注意事项
本文只针对使用 Scoop 安装 Windows Terminal 的情况,如果你通过应用商店安装,可以参考:
本文默认读者掌握基本的 Scoop 使用方法,不会详细讲解 Scoop 相关命令
本文撰写时间:2022年5月12日
环境:Windows 10 版本 21H1(内部版本 19043.1706)
Scoop版本:0.2.0
Windows Terminal版本:1.12.10982.0
PowerShell 版本:7.2.2
Windows Terminal 安装
scoop install windows-terminal
需要提前添加 extras
bucket
PowerShell 安装
必须保证 PowerShell 版本不低于 7.0
scoop install powershell
需要提前添加 dorado
bucket
sudo 安装
因为需要用管理员权限执行文件,故下载 sudo
顾名思义,这和 Linux 下的 sudo 命令是一个作用,获取管理员权限
scoop install sudo
需要提前添加 main
bucket
构建 install.ps1
文件并执行
在桌面(或其他目录下)新建一个 install.ps1
文件(为了版面舒适,该文件内容在本文末尾处,读者可自行前往复制)
切换到桌面(或其他目录下)使用 sudo
执行该文件
确认已经成功添加到右键菜单:
install.ps1
具体代码
代码来源: windowsterminal-shell-scoop/install.ps1
#Requires -RunAsAdministrator
#Requires -Version 6
[CmdletBinding()]
param(
[Parameter(Position = 0)]
[ValidateSet('Default', 'Flat', 'Mini')]
[string] $Layout = 'Default',
[Parameter()]
[switch] $PreRelease
)
function Generate-HelperScript(
# The cache folder
[Parameter(Mandatory=$true)]
[string]$cache)
{
$content =
"Set shell = WScript.CreateObject(`"Shell.Application`")
executable = WSCript.Arguments(0)
folder = WScript.Arguments(1)
If Wscript.Arguments.Count > 2 Then
profile = WScript.Arguments(2)
' 0 at the end means to run this command silently
shell.ShellExecute `"powershell`", `"Start-Process \`"`"`" & executable & `"\`"`" -ArgumentList \`"`"-p \`"`"\`"`"`" & profile & `"\`"`"\`"`" -d \`"`"\`"`"`" & folder & `"\`"`"\`"`" \`"`" `", `"`", `"runas`", 0
Else
' 0 at the end means to run this command silently
shell.ShellExecute `"powershell`", `"Start-Process \`"`"`" & executable & `"\`"`" -ArgumentList \`"`"-d \`"`"\`"`"`" & folder & `"\`"`"\`"`" \`"`" `", `"`", `"runas`", 0
End If
"
Set-Content -Path "$cache/helper.vbs" -Value $content
}
# https://github.com/Duffney/PowerShell/blob/master/FileSystems/Get-Icon.ps1
Function Get-Icon {
[CmdletBinding()]
Param (
[Parameter(Mandatory=$True, Position=1, HelpMessage="Enter the location of the .EXE file")]
[string]$File,
# If provided, will output the icon to a location
[Parameter(Position=1, ValueFromPipelineByPropertyName=$true)]
[string]$OutputFile
)
[System.Reflection.Assembly]::LoadWithPartialName('System.Drawing') | Out-Null
[System.Drawing.Icon]::ExtractAssociatedIcon($File).ToBitmap().Save($OutputFile)
}
# https://gist.github.com/darkfall/1656050
function ConvertTo-Icon
{
<#
.Synopsis
Converts image to icons
.Description
Converts an image to an icon
.Example
ConvertTo-Icon -File .\Logo.png -OutputFile .\Favicon.ico
#>
[CmdletBinding()]
param(
# The file
[Parameter(Mandatory=$true, Position=0, ValueFromPipelineByPropertyName=$true)]
[Alias('Fullname')]
[string]$File,
# If provided, will output the icon to a location
[Parameter(Position=1, ValueFromPipelineByPropertyName=$true)]
[string]$OutputFile
)
begin {
Add-Type -AssemblyName System.Drawing
}
process {
#region Load Icon
$resolvedFile = $ExecutionContext.SessionState.Path.GetResolvedPSPathFromPSPath($file)
if (-not $resolvedFile) {
return }
$inputBitmap = [Drawing.Image]::FromFile($resolvedFile)
$width = $inputBitmap.Width
$height = $inputBitmap.Height
$size = New-Object Drawing.Size $width, $height
$newBitmap = New-Object Drawing.Bitmap $inputBitmap, $size
#endregion Load Icon
#region Icon Size bound check
if ($width -gt 255 -or $height -gt 255) {
$ratio = ($height, $width | Measure-Object -Maximum).Maximum / 255
$width /= $ratio
$height /= $ratio
}
#endregion Icon Size bound check
#region Save Icon
$memoryStream = New-Object System.IO.MemoryStream
$newBitmap.Save($memoryStream, [System.Drawing.Imaging.ImageFormat]::Png)
$resolvedOutputFile = $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath($outputFile)
$output = [IO.File]::Create("$resolvedOutputFile")
$iconWriter = New-Object System.IO.BinaryWriter($output)
# 0-1 reserved, 0
$iconWriter.Write([byte]0)
$iconWriter.Write([byte]0)
# 2-3 image type, 1 = icon, 2 = cursor
$iconWriter.Write([short]1);
# 4-5 number of images
$iconWriter.Write([short]1)