是時候扔掉cmder, 換上Windows Terminal

作為一個Windows的長期用戶,一直沒有給款好用的終端,知道遇到了 cmder,它拯救一個習慣用Windows敲shell命令的人。

不用跟我安利macOS真香!公司上班一直用macOS,一方面確實更加習慣windows下面學習, 另一方面是上課需要Windows QQ共享桌面。

windows Terminal 1.0發佈,那麼是時候和 cmder 說再見了。

不過需要做一些配置和美化。

美化主題

  • 安裝posh-git和oh-my-posh
> Install-Module posh-git -Scope CurrentUser
> Install-Module oh-my-posh -Scope CurrentUser
  • 啟用默認設置
> Set-Prompt
  • 設置主題:
> Set-Theme Sorin

oh-my-posh 支持十幾種主題:

> Set-Theme

位於命令管道位置 1 的 cmdlet Set-Theme
請為以下參數提供值:
name: ?

警告: Theme ? not found. Available themes are:

Name                  Type     Location
----                  ----     --------
Agnoster              Defaults C:\Users\fnngj\Documents\WindowsPowerShell\Modules\oh-my-posh\2.0.412\Themes\Agnoster...
AgnosterPlus          Defaults C:\Users\fnngj\Documents\WindowsPowerShell\Modules\oh-my-posh\2.0.412\Themes\Agnoster...
Avit                  Defaults C:\Users\fnngj\Documents\WindowsPowerShell\Modules\oh-my-posh\2.0.412\Themes\Avit.psm1
Darkblood             Defaults C:\Users\fnngj\Documents\WindowsPowerShell\Modules\oh-my-posh\2.0.412\Themes\Darkbloo...
Fish                  Defaults C:\Users\fnngj\Documents\WindowsPowerShell\Modules\oh-my-posh\2.0.412\Themes\Fish.psm1
Honukai               Defaults C:\Users\fnngj\Documents\WindowsPowerShell\Modules\oh-my-posh\2.0.412\Themes\Honukai....
Paradox               Defaults C:\Users\fnngj\Documents\WindowsPowerShell\Modules\oh-my-posh\2.0.412\Themes\Paradox....
Powerlevel10k-Classic Defaults C:\Users\fnngj\Documents\WindowsPowerShell\Modules\oh-my-posh\2.0.412\Themes\Powerlev...
Powerlevel10k-Lean    Defaults C:\Users\fnngj\Documents\WindowsPowerShell\Modules\oh-my-posh\2.0.412\Themes\Powerlev...
PowerLine             Defaults C:\Users\fnngj\Documents\WindowsPowerShell\Modules\oh-my-posh\2.0.412\Themes\PowerLin...
pure                  Defaults C:\Users\fnngj\Documents\WindowsPowerShell\Modules\oh-my-posh\2.0.412\Themes\pure.psm1
robbyrussell          Defaults C:\Users\fnngj\Documents\WindowsPowerShell\Modules\oh-my-posh\2.0.412\Themes\robbyrus...
Sorin                 Defaults C:\Users\fnngj\Documents\WindowsPowerShell\Modules\oh-my-posh\2.0.412\Themes\Sorin.psm1
tehrob                Defaults C:\Users\fnngj\Documents\WindowsPowerShell\Modules\oh-my-posh\2.0.412\Themes\tehrob.psm1
  • 使用記事本打開PS配置文件(如無則創建該文件)
> if (!(Test-Path -Path $PROFILE )) { New-Item -Type File -Path $PROFILE -Force } notepad $PROFILE

隨後,在打開的記事本窗口裡,在文末加入下面內容,以讓Powershell在啟動之時應用主題,然後保存。(僅對當前用戶生效)

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

設置字體

如果你設置的主題出現亂碼,可以安裝SarasaGothic字體庫。

> scoop bucket add nerd-fonts
> scoop install SarasaGothic

或者直接到github下載:
//github.com/be5invis/Sarasa-Gothic/releases

然後,將字體庫解壓 複製到 C:\Windows\Font\ 目錄。

Windows Terminal 設置

點擊 Windows Terminal 向下箭頭,選擇設置,將會找打開一個配置文件。

// This file was initially generated by Windows Terminal 1.0.1401.0
// It should still be usable in newer versions, but newer versions might have additional
// settings, help text, or changes that you will not see unless you clear this file
// and let us generate a new one for you.
// To view the default settings, hold "alt" while clicking on the "Settings" button.
// For documentation on these settings, see: //aka.ms/terminal-documentation
{
    "$schema": "//aka.ms/terminal-profiles-schema",
    "defaultProfile": "{61c54bbd-c2c6-5271-96e7-009a87ff44bf}",
    // You can add more global application settings here.
    // To learn more about global settings, visit //aka.ms/terminal-global-settings
    // If enabled, selections are automatically copied to your clipboard.
    "copyOnSelect": false,
    // If enabled, formatted data is also copied to your clipboard
    "copyFormatting": false,
    // A profile specifies a command to execute paired with information about how it should look and feel.
    // Each one of them will appear in the 'New Tab' dropdown,
    //   and can be invoked from the commandline with `wt.exe -p xxx`
    // To learn more about profiles, visit //aka.ms/terminal-profile-settings
    "profiles": {
        "defaults": {
            // Put settings here that you want to apply to all profiles.
            "fontFace": "Sarasa Term Slab SC",  // 選擇字體,前面安裝的
            "backgroundImage" : "C:/Users/fnngj/Pictures/bg.jpg",  // 設置背景圖片
            "backgroundImageOpacity" : 0.9, // 背景圖片透明度
            "fontSize" : 16,  // 字體大小
            "foreground": "#76EE00"  //字體顏色
        },
       //...

當然,你也可以在繼續安裝vim 工具,來更加符合你的 shell習慣。

Tags: