搭建优雅的Windows终端 Windows terminal+scoop+starship

一、安装Windows terminal

Windows应用商店搜索下载Windows terminal
image

安装常用编程字体

下载编程英文字体,解压后全选字体——为所有用户安装

二、安装Powershell 7

打开PowerShell,输入下面命令选择安装一个版本

winget install --id Microsoft.Powershell --source winget

# 或者安装预览版的Powershell
winget install --id Microsoft.Powershell.Preview --source winget

三、使用Scoop

3.1 安装Scoop

Part from 搭建优雅编程环境

步骤 1:在 PowerShell 中打开远程权限

Set-ExecutionPolicy RemoteSigned -scope CurrentUser;

步骤 2:自定义 Scoop 安装目录

$env:SCOOP='Your_Scoop_Path'
[Environment]::SetEnvironmentVariable('SCOOP', $env:SCOOP, 'User')

如果跳过该步骤, Scoop 将默认把所有用户安装的 App 和 Scoop 本身置于C:\Users\user_name\scoop
步骤 3:下载并安装 Scoop

iwr -useb get.scoop.sh | iex
scoop update

上面无法下载的话,可以采用下方的国内镜像

iwr -useb https://gitee.com/glsnames/scoop-installer/raw/master/bin/install.ps1 | iex
scoop config SCOOP_REPO 'https://gitee.com/glsnames/scoop-installer'
scoop update

3.2 添加Scoop库

  • Scoop使用本地socks5代理
    以管理员权限打开powershell,编辑配置文件:
notepad $PROFILE

在配置文件中增加以下内容:

function proxyscoop {scoop config proxy 127.0.0.1:10809}
function unproxyscoop {scoop config rm proxy}

注意把10809改成自己本地sock5代理的端口

也可以顺便为git等添加代理命令的别名:

# 配置系统代理
function proxy {
    $env:HTTP_PROXY="http://127.0.0.1:10809"
    $env:HTTPS_PROXY="http://127.0.0.1:10809"
}
function unproxy {
    $env:HTTP_PROXY=""
    $env:HTTPS_PROXY=""
}

# 配置git代理
function unproxygit {git config --global --unset http.proxy && git config --global --unset https.proxy}
function proxygit {git config --global http.proxy socks5://127.0.0.1:10808 && git config --global https.proxy socks5://127.0.0.1:10808}

image

之后就可以使用proxyscoop命令启用Scoop代理,unproxyscoop命令取消Scoop代理。

  • 查看官方推荐仓库
$ scoop bucket known
main [默认]
extras [墙裂推荐]
versions
nightlies
nirsoft
php
nerd-fonts
nonportable
java
games
jetbrains
  • 分别下载git、extras、nerd-fonts等
# 安装git
scoop install git
# 添加额外库
scoop bucket add extras
scoop bucket add nerd-fonts
# scoop插件
scoop install scoop-completion
# 安装FiraCode-NF字体
scoop install FiraCode-NF
# 使用 Linux 命令行
scoop install gow
# 调用管理员权限
scoop install sudo

3.3 Scoop 的管理与配置

# 查看已安装程序
scoop list
# 查看更新
scoop status
# 删除旧版本
scoop cleanup
# 自身诊断
scoop checkup
# 搜索应用程序
scoop search <APPname>
# 卸载scoop
scoop uninstall scoop

安装一些常用编程字体

scoop install JetBrainsMono-NF
scoop install DejaVuSansMono-NF
scoop install CodeNewRoman-NF
scoop install SourceCodePro-NF
scoop install SarasaGothic-SC # 安装更纱黑体(简体中文)
scoop install Wenquanyi-Microhei # 安装文泉驿微米黑
scoop install Wenquanyi-Zenhei # 安装文泉驿正黑

四、Starship

4.1 安装启用starship

打开powershell,使用 Scoop 安装

scoop install starship

或者使用winget安装

winget install --id Starship.Starship

使用VScode打开配置文件

code $PROFILE

如果没有安装VScode,也可以使用notepad $PROFILE命令,通过记事本打开并编辑配置文件

配置文件中添加:

Invoke-Expression (&starship init powershell)

4.2 Windows terminal配置

打开下拉菜单——设置——左下角齿轮图标,编辑json配置文件
image

全选删除,粘贴以下内容

点击查看代码
{
    "$help": "https://aka.ms/terminal-documentation",
    "$schema": "https://aka.ms/terminal-profiles-schema",
    "actions": 
    [
        {
            "command": 
            {
                "action": "copy",
                "singleLine": false
            },
            "keys": "ctrl+c"
        },
        {
            "command": "paste",
            "keys": "ctrl+v"
        },
        {
            "command": "find",
            "keys": "ctrl+shift+f"
        },
        {
            "command": 
            {
                "action": "splitPane",
                "split": "auto",
                "splitMode": "duplicate"
            },
            "keys": "alt+shift+d"
        }
    ],
    "copyFormatting": "none",
    "copyOnSelect": true,
    "defaultProfile": "{574e775e-4f2a-5b96-ac1e-a2962a402336}",
    "newTabMenu": 
    [
        {
            "type": "remainingProfiles"
        }
    ],
    "profiles": 
    {
        "defaults": 
        {
            "opacity": 85,
            "useAcrylic": true
        },
        "list": 
        [
            {
                "backgroundImageOpacity": 0.25,
                "closeOnExit": "graceful",
                "colorScheme": "Aurora",
                "cursorColor": "#FFFFFF",
                "cursorShape": "filledBox",
                "font": 
                {
                    "face": "DejaVuSansMono Nerd Font",
                    "size": 12.0
                },
                "guid": "{61c54bbd-c2c6-5271-96e7-009a87ff44bf}",
                "historySize": 8001,
                "name": "Windows PowerShell",
                "opacity": 85,
                "padding": "0, 0, 0, 0",
                "snapOnInput": true,
                "startingDirectory": "%USERPROFILE%",
                "useAcrylic": true
            },
            {
                "colorScheme": "Afterglow",
                "font": 
                {
                    "face": "CodeNewRoman Nerd Font"
                },
                "guid": "{0caa0dad-35be-5f56-a8ff-afceeeaa6101}",
                "hidden": false,
                "name": "\u547d\u4ee4\u63d0\u793a\u7b26",
                "opacity": 85,
                "useAcrylic": true
            },
            {
                "colorScheme": "AdventureTime",
                "font": 
                {
                    "face": "CodeNewRoman Nerd Font"
                },
                "guid": "{b453ae62-4e3d-5e58-b989-0a998ec441b8}",
                "hidden": false,
                "name": "Azure Cloud Shell",
                "opacity": 85,
                "source": "Windows.Terminal.Azure",
                "useAcrylic": true
            },
            {
                "colorScheme": "One Half Dark",
                "font": 
                {
                    "face": "DejaVuSansMono Nerd Font"
                },
                "guid": "{2ece5bfe-50ed-5f3a-ab87-5cd4baafed2b}",
                "hidden": false,
                "name": "Git Bash",
                "opacity": 85,
                "source": "Git",
                "useAcrylic": true
            },
            {
                "closeOnExit": "graceful",
                "colorScheme": "Homebrew",
                "cursorColor": "#FFFFFF",
                "cursorShape": "bar",
                "font": 
                {
                    "face": "FiraCode Nerd Font"
                },
                "guid": "{574e775e-4f2a-5b96-ac1e-a2962a402336}",
                "hidden": false,
                "historySize": 9001,
                "name": "PowerShell 7",
                "opacity": 85,
                "padding": "5, 5, 20, 25",
                "snapOnInput": true,
                "source": "Windows.Terminal.PowershellCore",
                "startingDirectory": ".",
                "useAcrylic": true
            },
            {
                "colorScheme": "Ubuntu",
                "font": 
                {
                    "face": "CodeNewRoman Nerd Font",
                    "size": 13.0
                },
                "guid": "{17bf3de4-5353-5709-bcf9-835bd952a95e}",
                "hidden": false,
                "name": "Ubuntu-22.04",
                "opacity": 85,
                "source": "Windows.Terminal.Wsl",
                "tabTitle": "Ubuntu22.04",
                "useAcrylic": true
            },
            {
                "guid": "{6675430a-4476-5db5-a4a7-041850c93e5a}",
                "hidden": true,
                "name": "Developer Command Prompt for VS 2019",
                "source": "Windows.Terminal.VisualStudio"
            },
            {
                "guid": "{ec76e47a-f9ab-5e4a-b71f-f9c5e50614c4}",
                "hidden": true,
                "name": "Developer PowerShell for VS 2019",
                "source": "Windows.Terminal.VisualStudio"
            }
        ]
    },
    "schemes": 
    [
        {
            "background": "#1F1D45",
            "black": "#050404",
            "blue": "#0F4AC6",
            "brightBlack": "#4E7CBF",
            "brightBlue": "#1997C6",
            "brightCyan": "#C8FAF4",
            "brightGreen": "#9EFF6E",
            "brightPurple": "#9B5953",
            "brightRed": "#FC5F5A",
            "brightWhite": "#F6F5FB",
            "brightYellow": "#EFC11A",
            "cursorColor": "#FFFFFF",
            "cyan": "#70A598",
            "foreground": "#F8DCC0",
            "green": "#4AB118",
            "name": "AdventureTime",
            "purple": "#665993",
            "red": "#BD0013",
            "selectionBackground": "#FFFFFF",
            "white": "#F8DCC0",
            "yellow": "#E7741E"
        },
        {
            "background": "#212121",
            "black": "#151515",
            "blue": "#6C99BB",
            "brightBlack": "#505050",
            "brightBlue": "#6C99BB",
            "brightCyan": "#7DD6CF",
            "brightGreen": "#7E8E50",
            "brightPurple": "#9F4E85",
            "brightRed": "#AC4142",
            "brightWhite": "#F5F5F5",
            "brightYellow": "#E5B567",
            "cursorColor": "#D0D0D0",
            "cyan": "#7DD6CF",
            "foreground": "#D0D0D0",
            "green": "#7E8E50",
            "name": "Afterglow",
            "purple": "#9F4E85",
            "red": "#AC4142",
            "selectionBackground": "#303030",
            "white": "#D0D0D0",
            "yellow": "#E5B567"
        },
        {
            "background": "#23262E",
            "black": "#23262E",
            "blue": "#0321D7",
            "brightBlack": "#4E7CBF",
            "brightBlue": "#03D6B8",
            "brightCyan": "#03D6B8",
            "brightGreen": "#8FD46D",
            "brightPurple": "#EE5D43",
            "brightRed": "#F92672",
            "brightWhite": "#C74DED",
            "brightYellow": "#FFE66D",
            "cursorColor": "#EE5D43",
            "cyan": "#03D6B8",
            "foreground": "#FFCA28",
            "green": "#8FD46D",
            "name": "Aurora",
            "purple": "#EE5D43",
            "red": "#F0266F",
            "selectionBackground": "#292E38",
            "white": "#C74DED",
            "yellow": "#FFE66D"
        },
        {
            "background": "#1F2430",
            "black": "#191E2A",
            "blue": "#6DCBFA",
            "brightBlack": "#686868",
            "brightBlue": "#73D0FF",
            "brightCyan": "#95E6CB",
            "brightGreen": "#BAE67E",
            "brightPurple": "#D4BFFF",
            "brightRed": "#F28779",
            "brightWhite": "#FFFFFF",
            "brightYellow": "#FFD580",
            "cursorColor": "#FFCC66",
            "cyan": "#90E1C6",
            "foreground": "#CBCCC6",
            "green": "#A6CC70",
            "name": "Ayu Mirage",
            "purple": "#CFBAFA",
            "red": "#ED8274",
            "selectionBackground": "#33415E",
            "white": "#C7C7C7",
            "yellow": "#FAD07B"
        },
        {
            "background": "#0C0C0C",
            "black": "#0C0C0C",
            "blue": "#0037DA",
            "brightBlack": "#767676",
            "brightBlue": "#3B78FF",
            "brightCyan": "#61D6D6",
            "brightGreen": "#16C60C",
            "brightPurple": "#B4009E",
            "brightRed": "#E74856",
            "brightWhite": "#F2F2F2",
            "brightYellow": "#F9F1A5",
            "cursorColor": "#FFFFFF",
            "cyan": "#3A96DD",
            "foreground": "#CCCCCC",
            "green": "#13A10E",
            "name": "Campbell",
            "purple": "#881798",
            "red": "#C50F1F",
            "selectionBackground": "#FFFFFF",
            "white": "#CCCCCC",
            "yellow": "#C19C00"
        },
        {
            "background": "#012456",
            "black": "#0C0C0C",
            "blue": "#0037DA",
            "brightBlack": "#767676",
            "brightBlue": "#3B78FF",
            "brightCyan": "#61D6D6",
            "brightGreen": "#16C60C",
            "brightPurple": "#B4009E",
            "brightRed": "#E74856",
            "brightWhite": "#F2F2F2",
            "brightYellow": "#F9F1A5",
            "cursorColor": "#FFFFFF",
            "cyan": "#3A96DD",
            "foreground": "#CCCCCC",
            "green": "#13A10E",
            "name": "Campbell Powershell",
            "purple": "#881798",
            "red": "#C50F1F",
            "selectionBackground": "#FFFFFF",
            "white": "#CCCCCC",
            "yellow": "#C19C00"
        },
        {
            "background": "#FFFFFF",
            "black": "#3C5712",
            "blue": "#17B2FF",
            "brightBlack": "#749B36",
            "brightBlue": "#27B2F6",
            "brightCyan": "#13A8C0",
            "brightGreen": "#89AF50",
            "brightPurple": "#F2A20A",
            "brightRed": "#F49B36",
            "brightWhite": "#741274",
            "brightYellow": "#991070",
            "cursorColor": "#FFFFFF",
            "cyan": "#3C96A6",
            "foreground": "#000000",
            "green": "#6AAE08",
            "name": "Frost",
            "purple": "#991070",
            "red": "#8D0C0C",
            "selectionBackground": "#FFFFFF",
            "white": "#6E386E",
            "yellow": "#991070"
        },
        {
            "background": "#283033",
            "black": "#000000",
            "blue": "#6666E9",
            "brightBlack": "#D8E3F4",
            "brightBlue": "#0000FF",
            "brightCyan": "#00E5E5",
            "brightGreen": "#00D900",
            "brightPurple": "#E500E5",
            "brightRed": "#E50000",
            "brightWhite": "#E5E5E5",
            "brightYellow": "#E5E500",
            "cursorColor": "#FFFFFF",
            "cyan": "#00A6B2",
            "foreground": "#C7C7C7",
            "green": "#00A600",
            "name": "Homebrew",
            "purple": "#B200B2",
            "red": "#FC5275",
            "selectionBackground": "#FFFFFF",
            "white": "#BFBFBF",
            "yellow": "#999900"
        },
        {
            "background": "#282C34",
            "black": "#282C34",
            "blue": "#61AFEF",
            "brightBlack": "#5A6374",
            "brightBlue": "#61AFEF",
            "brightCyan": "#56B6C2",
            "brightGreen": "#98C379",
            "brightPurple": "#C678DD",
            "brightRed": "#E06C75",
            "brightWhite": "#DCDFE4",
            "brightYellow": "#E5C07B",
            "cursorColor": "#FFFFFF",
            "cyan": "#56B6C2",
            "foreground": "#DCDFE4",
            "green": "#98C379",
            "name": "One Half Dark",
            "purple": "#C678DD",
            "red": "#E06C75",
            "selectionBackground": "#FFFFFF",
            "white": "#DCDFE4",
            "yellow": "#E5C07B"
        },
        {
            "background": "#FAFAFA",
            "black": "#383A42",
            "blue": "#0184BC",
            "brightBlack": "#4F525D",
            "brightBlue": "#61AFEF",
            "brightCyan": "#56B5C1",
            "brightGreen": "#98C379",
            "brightPurple": "#C577DD",
            "brightRed": "#DF6C75",
            "brightWhite": "#FFFFFF",
            "brightYellow": "#E4C07A",
            "cursorColor": "#4F525D",
            "cyan": "#0997B3",
            "foreground": "#383A42",
            "green": "#50A14F",
            "name": "One Half Light",
            "purple": "#A626A4",
            "red": "#E45649",
            "selectionBackground": "#FFFFFF",
            "white": "#FAFAFA",
            "yellow": "#C18301"
        },
        {
            "background": "#002B36",
            "black": "#002B36",
            "blue": "#268BD2",
            "brightBlack": "#073642",
            "brightBlue": "#839496",
            "brightCyan": "#93A1A1",
            "brightGreen": "#586E75",
            "brightPurple": "#6C71C4",
            "brightRed": "#CB4B16",
            "brightWhite": "#FDF6E3",
            "brightYellow": "#657B83",
            "cursorColor": "#FFFFFF",
            "cyan": "#2AA198",
            "foreground": "#839496",
            "green": "#859900",
            "name": "Solarized Dark",
            "purple": "#D33682",
            "red": "#DC322F",
            "selectionBackground": "#FFFFFF",
            "white": "#EEE8D5",
            "yellow": "#B58900"
        },
        {
            "background": "#FDF6E3",
            "black": "#002B36",
            "blue": "#268BD2",
            "brightBlack": "#073642",
            "brightBlue": "#839496",
            "brightCyan": "#93A1A1",
            "brightGreen": "#586E75",
            "brightPurple": "#6C71C4",
            "brightRed": "#CB4B16",
            "brightWhite": "#FDF6E3",
            "brightYellow": "#657B83",
            "cursorColor": "#002B36",
            "cyan": "#2AA198",
            "foreground": "#657B83",
            "green": "#859900",
            "name": "Solarized Light",
            "purple": "#D33682",
            "red": "#DC322F",
            "selectionBackground": "#FFFFFF",
            "white": "#EEE8D5",
            "yellow": "#B58900"
        },
        {
            "background": "#000000",
            "black": "#000000",
            "blue": "#3465A4",
            "brightBlack": "#555753",
            "brightBlue": "#729FCF",
            "brightCyan": "#34E2E2",
            "brightGreen": "#8AE234",
            "brightPurple": "#AD7FA8",
            "brightRed": "#EF2929",
            "brightWhite": "#EEEEEC",
            "brightYellow": "#FCE94F",
            "cursorColor": "#FFFFFF",
            "cyan": "#06989A",
            "foreground": "#D3D7CF",
            "green": "#4E9A06",
            "name": "Tango Dark",
            "purple": "#75507B",
            "red": "#CC0000",
            "selectionBackground": "#FFFFFF",
            "white": "#D3D7CF",
            "yellow": "#C4A000"
        },
        {
            "background": "#FFFFFF",
            "black": "#000000",
            "blue": "#3465A4",
            "brightBlack": "#555753",
            "brightBlue": "#729FCF",
            "brightCyan": "#34E2E2",
            "brightGreen": "#8AE234",
            "brightPurple": "#AD7FA8",
            "brightRed": "#EF2929",
            "brightWhite": "#EEEEEC",
            "brightYellow": "#FCE94F",
            "cursorColor": "#000000",
            "cyan": "#06989A",
            "foreground": "#555753",
            "green": "#4E9A06",
            "name": "Tango Light",
            "purple": "#75507B",
            "red": "#CC0000",
            "selectionBackground": "#FFFFFF",
            "white": "#D3D7CF",
            "yellow": "#C4A000"
        },
        {
            "background": "#300A24",
            "black": "#2E3436",
            "blue": "#3465A4",
            "brightBlack": "#555753",
            "brightBlue": "#729FCF",
            "brightCyan": "#34E2E2",
            "brightGreen": "#8AE234",
            "brightPurple": "#AD7FA8",
            "brightRed": "#EF2929",
            "brightWhite": "#EEEEEC",
            "brightYellow": "#FCE94F",
            "cursorColor": "#FFFFFF",
            "cyan": "#06989A",
            "foreground": "#EEEEEC",
            "green": "#4E9A06",
            "name": "Ubuntu",
            "purple": "#75507B",
            "red": "#CC0000",
            "selectionBackground": "#FFFFFF",
            "white": "#D3D7CF",
            "yellow": "#C4A000"
        },
        {
            "background": "#300A24",
            "black": "#171421",
            "blue": "#0037DA",
            "brightBlack": "#767676",
            "brightBlue": "#08458F",
            "brightCyan": "#2C9FB3",
            "brightGreen": "#26A269",
            "brightPurple": "#A347BA",
            "brightRed": "#C01C28",
            "brightWhite": "#F2F2F2",
            "brightYellow": "#A2734C",
            "cursorColor": "#FFFFFF",
            "cyan": "#3A96DD",
            "foreground": "#FFFFFF",
            "green": "#26A269",
            "name": "Ubuntu-22.04-ColorScheme",
            "purple": "#881798",
            "red": "#C21A23",
            "selectionBackground": "#FFFFFF",
            "white": "#CCCCCC",
            "yellow": "#A2734C"
        },
        {
            "background": "#000000",
            "black": "#000000",
            "blue": "#000080",
            "brightBlack": "#808080",
            "brightBlue": "#0000FF",
            "brightCyan": "#00FFFF",
            "brightGreen": "#00FF00",
            "brightPurple": "#FF00FF",
            "brightRed": "#FF0000",
            "brightWhite": "#FFFFFF",
            "brightYellow": "#FFFF00",
            "cursorColor": "#FFFFFF",
            "cyan": "#008080",
            "foreground": "#C0C0C0",
            "green": "#008000",
            "name": "Vintage",
            "purple": "#800080",
            "red": "#800000",
            "selectionBackground": "#FFFFFF",
            "white": "#C0C0C0",
            "yellow": "#808000"
        }
    ],
    "themes": []
}
保存文件,退出。

4.3 PSReadLine

  • 安装
    打开Windows terminal,输入以下命令:
Install-Module PowerShellGet -scope CurrentUser -Force -AllowClobber
Install-Module PSReadLine -scope CurrentUser -Force
  • 配置
    打开配置文件
code $PROFILE

添加以下配置

Import-Module PSReadLine

Set-PSReadlineKeyHandler -Key Tab -Function Complete
Set-PSReadLineKeyHandler -Key "Ctrl+d" -Function MenuComplete
Set-PSReadLineKeyHandler -Key "Ctrl+z" -Function Undo
Set-PSReadLineKeyHandler -Key UpArrow -Function HistorySearchBackward
Set-PSReadLineKeyHandler -Key DownArrow -Function HistorySearchForward

image

4.4 整合Scoop

打开Windows terminal,输入以下命令:

Import-Module "$($(Get-Item $(Get-Command scoop).Path).Directory.Parent.FullName)\modules\scoop-completion"
Import-Module "$($(Get-Item $(Get-Command scoop).Path).Directory.Parent.FullName)\modules\scoop-completion" -ErrorAction SilentlyContinue

五、效果图

如下图,配置成功后,就可以在Windows terminal中使用Linux命令和终端快捷键(如使用Ctrl+l清屏),并且颜值也很高~
image

posted @ 2022-10-20 21:40  云吱  阅读(1995)  评论(1编辑  收藏  举报