像MAC一樣使用win10的Terminal(精簡版)

之前寫了《像MAC一樣使用win10的Terminal》,因為里面寫的內(nèi)容過于復(fù)雜猛遍,評論里會有很多人提問馋记,現(xiàn)在根據(jù)Windows 10 1909版本,出個更簡單的方式懊烤。

廢話不多說梯醒,上圖:


美化后的Windows Terminal

一. 安裝

直接進入Microsoft Store:


Windows Terminal

二. 復(fù)制我的配置文件

使用notepad $PROFILE即可打開

注意:如果沒有$PROFILE文件的話,可以先執(zhí)行:

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

然后notepad $PROFILE腌紧,粘貼我的配置:

Import-Module Get-ChildItemColor

$env:PYTHONIOENCODING="utf-8"
# Remove curl alias
If (Test-Path Alias:curl) {Remove-Item Alias:curl}
If (Test-Path Alias:curl) {Remove-Item Alias:curl}
# Remove-Item alias:ls -force
Set-Alias l Get-ChildItemColor -option AllScope
Set-Alias ls Get-ChildItemColorFormatWide -option AllScope

function GitLogPretty {
  git log --graph --pretty='%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --all
}

function PrettyLS {
  colorls --light -A
}

function GitStat {git status}

function GoBack {Set-Location ..}

function GetMyIp {curl -L tool.lu/ip}
function UpdateScoop {scoop update; scoop update *}

function UpdateChoco {choco upgrade chocolatey}

Import-Module posh-git
Import-Module oh-my-posh
# $DefaultUser = 'spenc'

# Setup other alias
Set-Alias open Invoke-Item
Set-Alias .. GoBack
Set-Alias glola GitLogPretty
Set-Alias gst GitStat
Set-Alias myip GetMyIp
Set-Alias pls PrettyLS

# Set theme
Set-Theme robbyrussell

Set-PSReadlineKeyHandler -Key Tab -Function MenuComplete

可能會有提示報錯之類的茸习,不急,我們再繼續(xù)安裝關(guān)聯(lián)的內(nèi)容壁肋。
因為我的1909版本還沒有winget号胚,所以還是使用ScoopChoco來安裝相關(guān)信息

三.安裝Scoop

  1. 訪問Scoop官網(wǎng)

  2. 安裝

Invoke-Expression (New-Object System.Net.WebClient).DownloadString('https://get.scoop.sh')

# 或者使用精簡命令安裝
iwr -useb get.scoop.sh | iex

如果安裝報錯籽慢,請先執(zhí)行下面操作

Set-ExecutionPolicy RemoteSigned -scope CurrentUser

四. 安裝字體

如果沒安裝這種字體,后邊安裝樣式的時候猫胁,會有亂碼情況

Fantasque Sans Mono Nerd Font

# 搜索 nerd fonts箱亿,這里選擇是的FantasqueSansMono這個字體
scoop search FantasqueSansMono-NF
# 添加 nerd fonts 源
scoop bucket add 'nerd-fonts'
# 安裝 nerd fonts
scoop install FantasqueSansMono-NF

注意:
這里可能會提示安裝git,用scoop install git就行了弃秆。
另外届惋,如果安裝一半失敗了,記得一定要先scoop uninstall xx菠赚,再進行scoop install xxx脑豹。

五. 安裝 Choco

  1. 以管理員方式運行Windows Terminal 或者 Power Shell

  2. 執(zhí)行命令

Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))

六. 安裝oh-my-posh(類似oh-my-zsh

  1. 安裝 posh-gitoh-my-posh
Install-Module posh-git -Scope CurrentUser
Install-Module oh-my-posh -Scope CurrentUser
  1. 如果沒有使用我的配置,請粘貼以下內(nèi)容進 PROFILE 文件
Import-Module posh-git
Import-Module oh-my-posh
# 設(shè)置樣式Paradox
Set-Theme Paradox

參考:

到這里锈至,就已經(jīng)基本結(jié)束了晨缴。

因為我的配置里有對ls命令的綁定,所以峡捡,還得優(yōu)化一下ls效果

七. 優(yōu)化ls命令

  1. 安裝get-childitemcolor
choco install get-childitemcolor
  1. 引用get-childitemcolor
Import-Module Get-ChildItemColor

參考:
《ChildItemColor: Add coloring to the output of Get-ChildItem Cmdlet of PowerShell》

這樣击碗,就正式的全部搞定了!

八. 如果想跟我的樣式一模一樣们拙,還需要Window Terminal的配置改一下

主要就是對每個Ternimal設(shè)置面板新式:

"fontFace" : "Cascadia Code",  // 字體
"useAcrylic": true, // 是否開啟透明度
"acrylicOpacity": 0.7,  // 面板透明度
"colorScheme": "One Half Dark",  // 顏色主題
"backgroundImageOpacity" : 0.3,  // 背景圖片透明度(我這里是預(yù)留的稍途,我沒有設(shè)置背景圖片)
"backgroundImageStretchMode" : "fill"  // 背景圖片填充方式

注意:
想要半透明效果的前提是系統(tǒng)已經(jīng)開啟了半透明,如圖:


系統(tǒng)開啟半透明效果

不想折騰的砚婆,直接復(fù)制我的配置:

// This file was initially generated by Windows Terminal 1.4.3243.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: https://aka.ms/terminal-documentation
{
    "$schema": "https://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 https://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 https://aka.ms/terminal-profile-settings
    "profiles":
    {
        "defaults":
        {
            // Put settings here that you want to apply to all profiles.
        },
        "list":
        [
            {
                // Make changes here to the powershell.exe profile.
                "guid": "{61c54bbd-c2c6-5271-96e7-009a87ff44bf}",
                "name": "Windows PowerShell",
                "commandline": "powershell.exe",
                "hidden": false,
                "fontFace" : "Cascadia Code",
                "useAcrylic": true,
                "acrylicOpacity": 0.7,
                "colorScheme": "One Half Dark",
                "backgroundImageOpacity" : 0.3,
                "backgroundImageStretchMode" : "fill"
            },
            {
                // Make changes here to the cmd.exe profile.
                "guid": "{0caa0dad-35be-5f56-a8ff-afceeeaa6101}",
                "name": "Command Prompt",
                "commandline": "cmd.exe",
                "hidden": false,
                "fontFace" : "Cascadia Code",
                "useAcrylic": true,
                "acrylicOpacity": 0.9,
                "colorScheme": "One Half Dark",
                "backgroundImageOpacity" : 0.3,
                "backgroundImageStretchMode" : "fill"
            },
            {
                "guid": "{b453ae62-4e3d-5e58-b989-0a998ec441b8}",
                "hidden": false,
                "name": "Azure Cloud Shell",
                "source": "Windows.Terminal.Azure",
                "fontFace" : "Cascadia Code",
                "useAcrylic": true,
                "acrylicOpacity": 0.9,
                "colorScheme": "One Half Dark",
                "backgroundImageOpacity" : 0.3,
                "backgroundImageStretchMode" : "fill"
            }
        ]
    },

    // Add custom color schemes to this array.
    // To learn more about color schemes, visit https://aka.ms/terminal-color-schemes
    "schemes": [],

    // Add custom actions and keybindings to this array.
    // To unbind a key combination from your defaults.json, set the command to "unbound".
    // To learn more about actions and keybindings, visit https://aka.ms/terminal-keybindings
    "actions":
    [
        // Copy and paste are bound to Ctrl+Shift+C and Ctrl+Shift+V in your defaults.json.
        // These two lines additionally bind them to Ctrl+C and Ctrl+V.
        // To learn more about selection, visit https://aka.ms/terminal-selection
        { "command": {"action": "copy", "singleLine": false }, "keys": "ctrl+c" },
        { "command": "paste", "keys": "ctrl+v" },

        // Press Ctrl+Shift+F to open the search box
        { "command": "find", "keys": "ctrl+shift+f" },

        // Press Alt+Shift+D to open a new pane.
        // - "split": "auto" makes this pane open in the direction that provides the most surface area.
        // - "splitMode": "duplicate" makes the new pane use the focused pane's profile.
        // To learn more about panes, visit https://aka.ms/terminal-panes
        { "command": { "action": "splitPane", "split": "auto", "splitMode": "duplicate" }, "keys": "alt+shift+d" }
    ]
}

相關(guān)工具

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末械拍,一起剝皮案震驚了整個濱河市,隨后出現(xiàn)的幾起案子装盯,更是在濱河造成了極大的恐慌坷虑,老刑警劉巖,帶你破解...
    沈念sama閱讀 216,402評論 6 499
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件埂奈,死亡現(xiàn)場離奇詭異迄损,居然都是意外死亡,警方通過查閱死者的電腦和手機账磺,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,377評論 3 392
  • 文/潘曉璐 我一進店門芹敌,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人垮抗,你說我怎么就攤上這事氏捞。” “怎么了冒版?”我有些...
    開封第一講書人閱讀 162,483評論 0 353
  • 文/不壞的土叔 我叫張陵液茎,是天一觀的道長。 經(jīng)常有香客問我,道長豁护,這世上最難降的妖魔是什么哼凯? 我笑而不...
    開封第一講書人閱讀 58,165評論 1 292
  • 正文 為了忘掉前任,我火速辦了婚禮楚里,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘猎贴。我一直安慰自己班缎,他們只是感情好,可當(dāng)我...
    茶點故事閱讀 67,176評論 6 388
  • 文/花漫 我一把揭開白布她渴。 她就那樣靜靜地躺著达址,像睡著了一般。 火紅的嫁衣襯著肌膚如雪趁耗。 梳的紋絲不亂的頭發(fā)上沉唠,一...
    開封第一講書人閱讀 51,146評論 1 297
  • 那天,我揣著相機與錄音苛败,去河邊找鬼满葛。 笑死,一個胖子當(dāng)著我的面吹牛罢屈,可吹牛的內(nèi)容都是我干的嘀韧。 我是一名探鬼主播,決...
    沈念sama閱讀 40,032評論 3 417
  • 文/蒼蘭香墨 我猛地睜開眼缠捌,長吁一口氣:“原來是場噩夢啊……” “哼锄贷!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起曼月,我...
    開封第一講書人閱讀 38,896評論 0 274
  • 序言:老撾萬榮一對情侶失蹤谊却,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后哑芹,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體炎辨,經(jīng)...
    沈念sama閱讀 45,311評論 1 310
  • 正文 獨居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 37,536評論 2 332
  • 正文 我和宋清朗相戀三年绩衷,在試婚紗的時候發(fā)現(xiàn)自己被綠了蹦魔。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點故事閱讀 39,696評論 1 348
  • 序言:一個原本活蹦亂跳的男人離奇死亡咳燕,死狀恐怖勿决,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情招盲,我是刑警寧澤低缩,帶...
    沈念sama閱讀 35,413評論 5 343
  • 正文 年R本政府宣布,位于F島的核電站,受9級特大地震影響咆繁,放射性物質(zhì)發(fā)生泄漏讳推。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點故事閱讀 41,008評論 3 325
  • 文/蒙蒙 一玩般、第九天 我趴在偏房一處隱蔽的房頂上張望银觅。 院中可真熱鬧,春花似錦坏为、人聲如沸究驴。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,659評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽洒忧。三九已至,卻和暖如春够颠,著一層夾襖步出監(jiān)牢的瞬間熙侍,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 32,815評論 1 269
  • 我被黑心中介騙來泰國打工履磨, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留蛉抓,地道東北人。 一個月前我還...
    沈念sama閱讀 47,698評論 2 368
  • 正文 我出身青樓蹬耘,卻偏偏與公主長得像芝雪,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個殘疾皇子综苔,可洞房花燭夜當(dāng)晚...
    茶點故事閱讀 44,592評論 2 353

推薦閱讀更多精彩內(nèi)容