強化win10下的命令行 - 顏值和實用並存

強化win10下的命令行 - 顏值和實用並存

0x1 安裝 Windows Terminal

Microsoft Store 中下載 Windows Terminal 注意系統要求前端

<img src="https://image.yoouu.cn/2020/win10-terminal/win10-terminal.png" alt="win10-terminal" style="zoom:50%;" />git

0x2 安裝 PowerShell core

下載地址:https://github.com/PowerShell/PowerShell/releasesgithub

win10選擇 PowerShell-7.1.0-preview.7-win-x64.msi 這種安裝便可shell

<img src="https://image.yoouu.cn/2020/win10-terminal/poweishell-core.png" alt="poweishell-core" style="zoom:50%;" />json

0x3 安裝字體(可選)

FiraCode - 連字符字體小程序

<img src="https://image.yoouu.cn/sunseekerx/resource/FiraCode.svg" alt="FiraCode" style="zoom: 33%;" />windows

JetBrainsMono - IDEA 系字體,我的用的這個bash

0x4 安裝 PowerShell 模塊

0x1 輸入如下命令app

經過在 PowerShell 中執行下面的命令安裝, 以超級管理員運行 PowerShellsvg

右鍵桌面空白的地方選擇 PowerShell > Open Here as Administrator

CurrentUser 是僅爲當前用戶安裝模塊

!若是出現 PowerShell 由於在此係統上禁止運行腳本…

輸入如下命令

# 更改執行策略
set-ExecutionPolicy RemoteSigned

# 查看執行策略
get-ExecutionPolicy
Install-Module posh-git -Scope CurrentUser 
Install-Module oh-my-posh -Scope CurrentUser

0x2 若是下載慢的話可使用命令行代理

# 設置代理(填寫你本地的端口)
netsh winhttp set proxy 127.0.0.1:1080
# 取消代理
netsh winhttp reset proxy
# 查看代理
netsh winhttp show proxy

0x5 配置 PowerShell

0x1 輸入:

$PROFILE

# C:\Users\SunSeekerX\Documents\PowerShell\Microsoft.PowerShell_profile.ps1

0x2 繼續輸入:

if (!(Test-Path -Path $PROFILE )) { New-Item -Type File -Path $PROFILE -Force }
notepad $PROFILE

0x3 在打開的文件中添加Set-Theme Paradox 是設置默認主題

該文件是每次啓動 PowerShell 執行的文件,加載兩個模塊和設置主題。

其餘可選主題有

Agnoster、Avit、Darkblood、Fish、Honukai、Paradox、Sorin、tehrob

Import-Module posh-git
Import-Module oh-my-posh
Set-Theme Paradox

0x4 保存後關閉記事本, 在終端中輸入如下命令生效(這裏不要照抄 下面執行的 是 上文中$PROFILE的值)

C:\Users\SunSeekerX\Documents\PowerShell\Microsoft.PowerShell_profile.ps1

0x5 切換主題

Set-Theme 主題名字

0x6 配置 Windows Terminal

官網詳細配置說明

配置主題配色

0x1 打開配置文件 setting.json

<img src="https://image.yoouu.cn/2020/win10-terminal/pwsh.png" alt="pwsh" style="zoom: 50%;" />

0x2 參考如下配置

可自行修改,必定要符合json的內容格式,否則會報錯,還有就是圖片的的路徑要與己系統對應

改的比較多的就是 profiles > defaultsschemes ,前者是啓動的配置,後者是主題配色。

下面的配置不要所有複製,能夠選擇性的更改你的配置!

{
    "$schema": "https://aka.ms/terminal-profiles-schema",
    "defaultProfile": "{574e775e-4f2a-5b96-ac1e-a2962a402336}",
    "copyOnSelect": false,
    "copyFormatting": false,
    "profiles": {
        "defaults": {
            "fontFace": "JetBrains Mono", // oh-my-posh 主題緣由,使用其餘的字體可能會出現亂碼
            // "backgroundImage": "C:\\bash-bg.jpg", // 背景圖片地址
            // "backgroundImageOpacity": 0.5, // 透明度
            "colorScheme": "ayu", // 顏色方案
            "acrylicOpacity": 0.7,
            "useAcrylic": true
        },
        "list": [
            {
                // Make changes here to the powershell.exe profile.
                "guid": "{61c54bbd-c2c6-5271-96e7-009a87ff44bf}",
                "name": "Windows PowerShell",
                "commandline": "powershell.exe",
                "hidden": false,
                "startingDirectory": null
            },
            {
                // Make changes here to the cmd.exe profile.
                "guid": "{0caa0dad-35be-5f56-a8ff-afceeeaa6101}",
                "name": "命令提示符",
                "commandline": "cmd.exe",
                "hidden": false,
                "startingDirectory": null
            },
            {
                "guid": "{574e775e-4f2a-5b96-ac1e-a2962a402336}",
                "hidden": false,
                "name": "PowerShell",
                "source": "Windows.Terminal.PowershellCore",
                "startingDirectory": null
            },
            {
                "guid": "{b453ae62-4e3d-5e58-b989-0a998ec441b8}",
                "hidden": false,
                "name": "Azure Cloud Shell",
                "source": "Windows.Terminal.Azure",
                "startingDirectory": null
            }
        ]
    },
    // 配色方案
    "schemes": [
        {
            "name": "Andromeda",
            "black": "#000000",
            "red": "#cd3131",
            "green": "#05bc79",
            "yellow": "#09da0f",
            "blue": "#2472c8",
            "purple": "#bc3fbc",
            "cyan": "#0fa8cd",
            "white": "#e5e5e5",
            "brightBlack": "#666666",
            "brightRed": "#cd3131",
            "brightGreen": "#05bc79",
            "brightYellow": "#09da0f",
            "brightBlue": "#2472c8",
            "brightPurple": "#bc3fbc",
            "brightCyan": "#0fa8cd",
            "brightWhite": "#e5e5e5",
            "background": "#262a33",
            "foreground": "#e5e5e5"
        },
        {
            "name": "Campbell",
            "foreground": "#F2F2F2",
            "background": "#0C0C0C",
            "colors": [
                "#0C0C0C",
                "#C50F1F",
                "#13A10E",
                "#C19C00",
                "#0037DA",
                "#881798",
                "#3A96DD",
                "#CCCCCC",
                "#767676",
                "#E74856",
                "#16C60C",
                "#F9F1A5",
                "#3B78FF",
                "#B4009E",
                "#61D6D6",
                "#F2F2F2"
            ]
        },
        {
            "name": "Solarized Dark",
            "foreground": "#FDF6E3",
            "background": "#073642",
            "colors": [
                "#073642",
                "#D30102",
                "#859900",
                "#B58900",
                "#268BD2",
                "#D33682",
                "#2AA198",
                "#EEE8D5",
                "#002B36",
                "#CB4B16",
                "#586E75",
                "#657B83",
                "#839496",
                "#6C71C4",
                "#93A1A1",
                "#FDF6E3"
            ]
        },
        {
            "name": "ayu",
            "black": "#000000",
            "red": "#ff3333",
            "green": "#b8cc52",
            "yellow": "#e7c547",
            "blue": "#36a3d9",
            "purple": "#f07178",
            "cyan": "#95e6cb",
            "white": "#ffffff",
            "brightBlack": "#323232",
            "brightRed": "#ff6565",
            "brightGreen": "#eafe84",
            "brightYellow": "#fff779",
            "brightBlue": "#68d5ff",
            "brightPurple": "#ffa3aa",
            "brightCyan": "#c7fffd",
            "brightWhite": "#ffffff",
            "background": "#0f1419",
            "foreground": "#e6e1cf"
        }
    ],
    "keybindings": [
        {
            "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"
        }
    ]
}

0x3 官方更多配色

https://docs.microsoft.com/zh-cn/windows/terminal/customize-settings/color-schemes

添加 Windows Terminal 到右鍵

<img src="https://image.yoouu.cn/2020/win10-terminal/right-menu.png" alt="right-menu" style="zoom:50%;" />

0x1 下載圖標

下載地址:icon,放到 C:\Users\[user_name]\AppData\Local\terminal,沒有這個文件夾新建一個。

注意[user_name] 是你本身電腦的用戶名

0x2 寫入註冊表

建立一個txt文檔,並把檔後綴改成 reg。文檔的名字可本身建立,後綴名不能夠錯。右鍵菜單出現 Windows Terminal 有兩種方法。一種是按shift+ 右鍵,另外一種是直接右鍵

shift + 右鍵

把下面的內容複製到reg去

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\Directory\Background\shell\wt]
@="Windows Terminal"
"Icon"="%USERPROFILE%\\AppData\\Local\\terminal\\wt_32.ico"
"Extended"=""

[HKEY_CLASSES_ROOT\Directory\Background\shell\wt\command]
@="C:\\Users\\[user_name]\\AppData\\Local\\Microsoft\\WindowsApps\\wt.exe"

注意:請把 [user_name] 改爲本身電腦的用戶名

右鍵

把下面的內容複製到reg去

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\Directory\Background\shell\wt]
@="Windows terminal here"
"Icon"="%USERPROFILE%\\AppData\\Local\\terminal\\wt_32.ico"

[HKEY_CLASSES_ROOT\Directory\Background\shell\wt\command]
@="C:\\Users\\[user_name]\\AppData\\Local\\Microsoft\\WindowsApps\\wt.exe"

注意:請把 [user_name] 改爲本身電腦的用戶名

0x3 修改 Windows Terminal 的 settings.json

profiles > list > startingDirectory 改成 null,沒有的本身建立一個。

能夠選擇的改你須要的。(我都改了)

這個是修改右鍵啓動路徑爲當前運行命令的路徑。

0x7 結語

平時工做中命令行 git 命令用的比較多,安裝了擴展,輸入命令能夠按 Tab 來自動補全方便了不少。

Windows 下的命令行還有不少的玩法,好比支持 Linux 命令的 MSYS2,集成了 pacman。 能夠參考 Win10終端神器——Windows Terminal 與 MSYS2 MinGW64 集成記 進行安裝。

0x8 參考連接

關於我

SunSeekerX,前端開發、Nodejs開發、小程序、uni-app開發、等等

喜歡探討技術實現方案和細節,完美主義者,見不得bug

Github:https://github.com/SunSeekerX

我的博客:https://yoouu.cn/

我的在線筆記:https://sunseekerx.yoouu.cn/

相關文章
相關標籤/搜索