安装前准备

  • 进入 PowerShell Core 下载对应稳定版,然后依次点击直接同意直接安装
  • 接着是安装将要使用的终端界面字体FiraCode Nerd Font(这是我个人比较喜欢的一款终端界面字体,大家此处也可以自行选择)。由于它的下载速度比较慢,我将其存储到了百度网盘 ,大家也可以访问官网 下载,右键双击安装
  • 安装 Windows 的包管理 Scoop,关于下载使用可以参考我的这篇博客

PowerShell美化

主题设置

  • 打开下载好的 PowerShell,界面依旧比较丑,接下来开始美化 🍁🍊

在刚才下载的 PowerShell 中运行:

scoop update

# 可将 Powershell 的命令替换成对应的 Bash 命令
scoop install gow

# 安装 PSReadline 包,该插件可以让命令行很好用,类似 zsh
Install-Module -Name PSReadLine

编辑配置文件:

code $PROFILE

添加以下配置文件:

Invoke-Expression (&starship init powershell)
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

高亮 PowerShell 的 ls

# 高亮目录显示
Install-Module DirColors

# 打开配置文件 $PROFILE,添加
Import-Module DirColors

StarShip 美化

安装 StarShip 进行终端美化:

scoop install starship

生成 Starship 配置文件并修改

touch ~/.config/starship.toml

终端输入cd ~/.config编辑你的starship.toml文件添加以下配置代码,以下代码是我根据个人喜好以及需求设置的样式,采用FiraCode Nerd Font字体,由于网页字体原因,部分表情符号在以下代码未显示:

# row 1
# 1. #003543 #00CF85
# 2. #DA627D
# 3. #2E9599
# 4. #76B367
# 5. #83769C
# 6. #33658A
# 7. #2E9599
# row2
# #45F1C2 #D04379 #27D1E6 #45F1C2


format = """
[](#003543)\
$username\
[](bg:#DA627D fg:#003543)\
$directory\
[](fg:#DA627D bg:#2E9599)\
$git_branch\
$git_status\
[](fg:#2E9599 bg:#76B367)\
$conda\
[](fg:#76B367 bg:#83769C)\
$time\
[](fg:#83769C bg:#33658A)\
$cmd_duration\
[ ](fg:#33658A)
$character"""

[username]
show_always = true
style_user = "fg:#00CF85 bg:#003543"
style_root = "fg:#00CF85 bg:#003543"
format = '[🌱 tsh ]($style)'

[directory]
style = "bg:#DA627D"
format = "[  $path ]($style)"
truncation_length = 5
truncation_symbol = "~/"

[git_branch]
symbol = ""
style = "bg:#2E9599"
format = '[[ $symbol $branch ](bg:#2E9599)]($style)'

[git_status]
style = "bg:#2E9599"
format = '[[($all_status$ahead_behind )](bg:#2E9599)]($style)'

[nodejs]
symbol = ""
style = "bg:#76B367"
format = '[[ $symbol ($version) ](bg:#76B367)]($style)'

[conda]
symbol = " "
style = "bg:#76B367"
format = "[[ $symbol ($environment) ](bg:#76B367)]($style)"
ignore_base	 = true
disabled = false


[rust]
symbol = ""
style = "bg:#76B367"
format = '[[ $symbol ($version) ](bg:#76B367)]($style)'


[time]
disabled = false
time_format = "%R" # Hour:Minute Format
utc_time_offset = "+8"
style = "bg:#83769C"
format = '[[ 🕙 $time ](bg:#83769C)]($style)'

[line_break]
disabled = true


[character]
success_symbol = "[runner](bold fg:#D04379) [>](bold fg:#27D1E6)[>](bold fg:#45F1C2)"
error_symbol = "[ERROR](bold fg:#D04379) [>](bold fg:#27D1E6)[>](bold fg:#45F1C2)"


[cmd_duration]
style = "bg:#33658A"
min_time = 1
format = "[[ ♥  $duration ](bg:#33658A)]($style)"

Windows Terminal美化

安装Windows Terminal

scoop install windows-terminal

修改配置文件

点击设置——>打开JSON文件

找到对应的位置,添加以下配置参数

// *******  添加配置文件开始
"fontFace": "FiraCode Nerd Font",  // 修改字体
"fontSize": 15,                    // 字体大小
"colorScheme":"One Half Dark",     // 主题配色
"snapOnInput": true,               // 嗅探开启
"startingDirectory": "E:\\360_cloud\\360yun\\code",   // 初始路径

"useAcrylic":true,                 // 开启毛玻璃效果
"acrylicOpacity":0.5,              // 毛玻璃透明度

// 插入背景图片路径,注意路径斜杠转义
"backgroundImage":"C:\\Users\\shaohan.tian\\Pictures\\Camera Roll\\pure_black.jpg",
"backgroundImageStretchMode":"uniformToFill",        // 缩放方式
"backgroundImageAlignment":"center",                 // 对齐方式
"backgroundImageOpacity":0.5,                        // 透明度
// *******  添加配置文件结束

注意:这里的FiraCode Nerd Font字体在Windows Termina窗口显示是没有问题的,但是在原始的powershell中会显示乱码,就像这样:

这是由于这款字体本身不支持 Windows 终端显示:

临时方案:可以将 PowerShell 字体替换为MesloLGS NF Regular使用。

修改快捷键

原始的快捷键对我来说比较杂乱,我根据自己的使用习惯进行重新设置,这是我修改后的快捷键功能,大家可以考虑是否符合个人使用习惯

这里直接替换 JSON 设置文件中的“action”部分即可成功设置快捷键:

    [
        {
            "command": "unbound",
            "keys": "alt+f4"
        },
        {
            "command": "unbound",
            "keys": "ctrl+minus"
        },
        {
            "command": "unbound",
            "keys": "ctrl+numpad_minus"
        },
        {
            "command": "unbound",
            "keys": "ctrl+plus"
        },
        {
            "command": "unbound",
            "keys": "ctrl+shift+end"
        },
        {
            "command": "unbound",
            "keys": "ctrl+shift+home"
        },
        {
            "command": "unbound",
            "keys": "ctrl+shift+f"
        },
        {
            "command": "unbound",
            "keys": "alt+shift+minus"
        },
        {
            "command": "unbound",
            "keys": "ctrl+shift+pgup"
        },
        {
            "command": "unbound",
            "keys": "alt+shift+plus"
        },
        {
            "command": "unbound",
            "keys": "alt+shift+up"
        },
        {
            "command": "unbound",
            "keys": "alt+shift+down"
        },
        {
            "command": "unbound",
            "keys": "alt+shift+right"
        },
        {
            "command": "unbound",
            "keys": "alt+shift+left"
        },
        {
            "command": "unbound",
            "keys": "ctrl+0"
        },
        {
            "command": "unbound",
            "keys": "shift+insert"
        },
        {
            "command": "unbound",
            "keys": "ctrl+v"
        },
        {
            "command": "unbound",
            "keys": "win+sc(41)"
        },
        {
            "command": "unbound",
            "keys": "ctrl+alt+comma"
        },
        {
            "command": "unbound",
            "keys": "ctrl+comma"
        },
        {
            "command": "unbound",
            "keys": "alt+space"
        },
        {
            "command": "unbound",
            "keys": "ctrl+shift+space"
        },
        {
            "command": "unbound",
            "keys": "ctrl+insert"
        },
        {
            "command": "unbound",
            "keys": "ctrl+shift+pgdn"
        },
        {
            "command": "unbound",
            "keys": "alt+left"
        },
        {
            "command": "unbound",
            "keys": "alt+right"
        },
        {
            "command": "unbound",
            "keys": "alt+down"
        },
        {
            "command": "unbound",
            "keys": "alt+up"
        },
        {
            "command": "unbound",
            "keys": "alt+enter"
        },
        {
            "command": "unbound",
            "keys": "f11"
        },
        {
            "command": "unbound",
            "keys": "ctrl+numpad_plus"
        },
        {
            "command": "unbound",
            "keys": "ctrl+shift+v"
        },
        {
            "command": "unbound",
            "keys": "ctrl+shift+t"
        },
        {
            "command": "unbound",
            "keys": "ctrl+alt+9"
        },
        {
            "command": "unbound",
            "keys": "ctrl+shift+h"
        },
        {
            "command": "unbound",
            "keys": "ctrl+h"
        },
        {
            "command": "unbound",
            "keys": ""
        },
        {
            "command": "unbound",
            "keys": "ctrl+shift+o"
        },
        {
            "command": "unbound",
            "keys": "ctrl+alt+8"
        },
        {
            "command": "unbound",
            "keys": "ctrl+alt+7"
        },
        {
            "command": "unbound",
            "keys": "ctrl+alt+6"
        },
        {
            "command": "unbound",
            "keys": "ctrl+alt+5"
        },
        {
            "command": "unbound",
            "keys": "ctrl+alt+4"
        },
        {
            "command": "unbound",
            "keys": "ctrl+shift+9"
        },
        {
            "command": "unbound",
            "keys": "ctrl+shift+7"
        },
        {
            "command": "unbound",
            "keys": "ctrl+shift+5"
        },
        {
            "command": "unbound",
            "keys": "ctrl+shift+6"
        },
        {
            "command": "unbound",
            "keys": "ctrl+shift+8"
        },
        {
            "command": "unbound",
            "keys": "ctrl+shift+4"
        },
        {
            "command": 
            {
                "action": "copy",
                "singleLine": false
            },
            "keys": "ctrl+c"
        },
        {
            "command": "paste"
        },
        {
            "command": 
            {
                "action": "splitPane",
                "split": "right"
            },
            "keys": "ctrl+shift+right"
        },
        {
            "command": 
            {
                "action": "newTab"
            },
            "keys": "ctrl+t"
        },
        {
            "command": 
            {
                "action": "newTab"
            },
            "keys": "ctrl+n"
        },
        {
            "command": 
            {
                "action": "adjustFontSize",
                "delta": -1
            },
            "keys": "ctrl+shift+minus"
        },
        {
            "command": 
            {
                "action": "moveFocus",
                "direction": "up"
            },
            "keys": "ctrl+alt+up"
        },
        {
            "command": 
            {
                "action": "moveFocus",
                "direction": "previousInOrder"
            },
            "keys": "ctrl+shift+tab"
        },
        {
            "command": 
            {
                "action": "splitPane",
                "split": "down"
            },
            "keys": "ctrl+shift+down"
        },
        {
            "command": 
            {
                "action": "scrollUp"
            }
        },
        {
            "command": "find",
            "keys": "ctrl+f"
        },
        {
            "command": "toggleFullscreen",
            "keys": "ctrl+alt+p"
        },
        {
            "command": 
            {
                "action": "moveFocus",
                "direction": "right"
            },
            "keys": "ctrl+alt+right"
        },
        {
            "command": 
            {
                "action": "moveFocus",
                "direction": "left"
            },
            "keys": "ctrl+alt+left"
        },
        {
            "command": "closeWindow",
            "keys": "ctrl+shift+w"
        },
        {
            "command": 
            {
                "action": "scrollDown"
            },
            "keys": "ctrl+j"
        },
        {
            "command": 
            {
                "action": "scrollDown"
            },
            "keys": "ctrl+k"
        },
        {
            "command": "scrollToBottom"
        },
        {
            "command": 
            {
                "action": "setTabColor",
                "color": "#DA627D"
            },
            "keys": "ctrl+shift+i"
        },
        {
            "command": 
            {
                "action": "setTabColor",
                "color": "#F9F9F9"
            },
            "keys": "ctrl+shift+u"
        },
        {
            "command": 
            {
                "action": "splitPane",
                "split": "auto",
                "splitMode": "duplicate"
            },
            "keys": "alt+shift+d"
        },
        {
            "command": 
            {
                "action": "moveFocus",
                "direction": "nextInOrder"
            },
            "keys": "ctrl+tab"
        },
        {
            "command": "closePane",
            "keys": "ctrl+w"
        },
        {
            "command": "scrollUpPage"
        },
        {
            "command": 
            {
                "action": "findMatch",
                "direction": "prev"
            },
            "keys": "ctrl+shift+enter"
        },
        {
            "command": 
            {
                "action": "adjustFontSize",
                "delta": 1
            },
            "keys": "ctrl+shift+plus"
        },
        {
            "command": 
            {
                "action": "findMatch",
                "direction": "next"
            },
            "keys": "ctrl+enter"
        },
        {
            "command": 
            {
                "action": "splitPane",
                "split": "left"
            },
            "keys": "ctrl+shift+left"
        },
        {
            "command": 
            {
                "action": "openSettings",
                "target": "settingsUI"
            },
            "keys": "ctrl+shift+comma"
        },
        {
            "command": 
            {
                "action": "openSettings",
                "target": "settingsUI"
            },
            "keys": "ctrl+shift+p"
        },
        {
            "command": "scrollToTop"
        },
        {
            "command": 
            {
                "action": "splitPane",
                "split": "up"
            },
            "keys": "ctrl+shift+up"
        },
        {
            "command": 
            {
                "action": "moveFocus",
                "direction": "down"
            },
            "keys": "ctrl+alt+down"
        },
        {
            "command": 
            {
                "action": "moveFocus",
                "direction": "previous"
            }
        },
        {
            "command": "openSystemMenu"
        },
        {
            "command": 
            {
                "action": "commandPalette"
            },
            "keys": "ctrl+shift+c"
        },
        {
            "command": 
            {
                "action": "renameWindow"
            }
        },
        {
            "command": 
            {
                "action": "renameTab"
            }
        },
        {
            "command": "openWindowRenamer"
        },
        {
            "command": "openTabRenamer",
            "keys": "ctrl+m"
        },
        {
            "command": 
            {
                "action": "moveTab",
                "direction": "backward"
            }
        }
    ]

添加右键菜单

为了方便在某一特定目录直接打开Terminal,这里我们将其添加到右键快捷菜单,首先进入 微软github 下载 Terminal 图标,存入特定位置:

接着运行以下命令,注意将以下命令中的 图标存放位置Windows Terminal 安装位置 替换为 个人 存储路径:

$basePath = "Registry::HKEY_CLASSES_ROOT\Directory\Background\shell"
sudo New-Item -Path "$basePath\wt" -Force -Value "Windows Terminal"
sudo New-ItemProperty -Path "$basePath\wt" -Force -Name "Icon" -PropertyType ExpandString -Value "C:\Users\shaohan.tian\Pictures\Camera Roll\terminal.ico"
sudo New-Item -Path "$basePath\wt\command" -Force -Type ExpandString -Value '"C:\Users\shaohan.tian\scoop\apps\windows-terminal\1.12.10982.0\WindowsTerminal.exe" -p PowerShell -d "%V"'

到这里,整个终端的配置也就完成了,效果展示如下,各位慢慢享用 💥