之前寫了《像MAC一樣使用win10的Terminal》,因為里面寫的內(nèi)容過于復(fù)雜猛遍,評論里會有很多人提問馋记,現(xiàn)在根據(jù)Windows 10 1909版本,出個更簡單的方式懊烤。
廢話不多說梯醒,上圖:
一. 安裝
直接進入Microsoft Store:
二. 復(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
号胚,所以還是使用Scoop
和Choco
來安裝相關(guān)信息
三.安裝Scoop
安裝
Invoke-Expression (New-Object System.Net.WebClient).DownloadString('https://get.scoop.sh')
# 或者使用精簡命令安裝
iwr -useb get.scoop.sh | iex
如果安裝報錯籽慢,請先執(zhí)行下面操作
Set-ExecutionPolicy RemoteSigned -scope CurrentUser
四. 安裝字體
如果沒安裝這種字體,后邊安裝樣式的時候猫胁,會有亂碼情況
# 搜索 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
先
以管理員方式
運行Windows Terminal
或者Power Shell
執(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
)
- 安裝
posh-git
和oh-my-posh
Install-Module posh-git -Scope CurrentUser
Install-Module oh-my-posh -Scope CurrentUser
- 如果沒有使用我的配置,請粘貼以下內(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
命令
- 安裝
get-childitemcolor
choco install get-childitemcolor
- 引用
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)開啟了半透明,如圖:
不想折騰的砚婆,直接復(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" }
]
}