将Windows Terminal 添加到右键菜单,使用 Scoop 安装

这篇博客主要介绍了如何使用 Scoop 在 Windows 10 系统中安装 Windows Terminal,并将其添加到右键菜单。内容包括安装注意事项,PowerShell 的版本要求,sudo 的安装,以及创建和执行脚本来实现右键菜单的添加。适用于熟悉 Scoop 的用户。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

注意事项

本文只针对使用 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)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值