之前写过一篇文章vscode+wsl+windows terminal美化和搭建linux开发环境
wsl挺好用的,不过比较麻烦,而且windows下的liunx子系统不完整,很多东西不能用,毕竟不是虚拟机。看到powershell7,心动了,本篇文章就如标题所言美化命令行操作。
下载windows terminal
Microsoft Store就有下载
下载并安装powershell7
选个最新的就行,我下载的是7.1.0-preview3,powershell7下载
下载scoop或者 chocolatey (windows包管理工具)
也可以用powershell的Install-Module
,不过还是推荐使用scoop
或者chocolatey
以scoop
为例:
安装scoop
Invoke-Expression (New-Objec System.Net.WebClient).DownloadString('https://get.scoop.sh')
# or
iwr -useb get.scoop.sh | iex
美化powershell
这里主要用到两个包,PSReadLine命令行提示记录,starship美化显示样式,colortool颜色配置
-
安装
Install-Module -Name PSReadLine -AllowPrerelease -Force # PSReadLine scoop install colortool scoop install starship
-
写powershell的配置文件
打开配置文件
notepad.exe $Profile # or 用vscode code $Profile
写入
#-----------------------------------------------------PSReadline # 设置 Tab 键补全 Set-PSReadlineKeyHandler -Key Tab -Function Complete # 设置 Ctrl+d 为菜单补全和 Intellisense # Set-PSReadLineKeyHandler -Key "Tab" -Function MenuComplete # 设置 Ctrl+d 为退出 PowerShell Set-PSReadlineKeyHandler -Key "Ctrl+d" -Function ViExit # 设置 Ctrl+z 为撤销 Set-PSReadLineKeyHandler -Key "Ctrl+z" -Function Undo # 设置向上键为后向搜索历史记录 Set-PSReadLineKeyHandler -Key UpArrow -Function HistorySearchBackward # 设置向下键为前向搜索历史纪录 Set-PSReadLineKeyHandler -Key DownArrow -Function HistorySearchForward # 一些PSReadline配置 $PSReadLineOptions = @{ EditMode = "Emacs" HistoryNoDuplicates = $true HistorySearchCursorMovesToEnd = $true Colors = @{ # 提示文字颜色,原来的颜色太浅了,我这里换了 Prediction = '#8F8B8B' } } Set-PSReadLineOption @PSReadLineOptions #-----------------------------------------------------starship Invoke-Expression (&starship init powershell)
-
配置
starship
创建这个文件夹并创建
startship.toml
mkdir -p ~/.config && touch ~/.config/starship.toml
如果你创建失败,说明有这个
.config
这个文件夹,直接touch ~/.config/starship.toml
notepad.exe ~/.config/starship.toml # or code ~/.config/starship.toml
具体配置看官网,这里出现的小方框或者乱码是字体缺失,我这里用的是
FiraCode Nerd Font
字体,这个后面再说大概像这个样子
[character] symbol = "➜" [aws] symbol = " " [battery] full_symbol = "" charging_symbol = "" discharging_symbol = "" [conda] symbol = " " [docker] symbol = " " [elixir] symbol = " " [elm] symbol = " " [git_branch] symbol = " " [golang] symbol = " " [haskell] symbol = " " [hg_branch] symbol = " " [java] symbol = " " [julia] symbol = " " [memory_usage] symbol = " " [nix_shell] symbol = " " [nodejs] # symbol = " " symbol=" " [package] symbol = " " [php] symbol = " " [python] symbol = " " [ruby] symbol = " " [rust] symbol = " "
-
配置
colortool
colortool -s # 颜色表 colortool OneHalfDark.itermcolors # colortools后面跟主题名字就行
下载并配置FiraCode Nerd Font
字体
-
下载
FiraCode Nerd Font
字体打开nerdfonts网站,滑到最下面找到
FiraCode Nerd Font
下载解压,全选&右键安装
-
在
vscode
中配置字体打开
vscode
配置文件,写入"editor.fontFamily": "FiraCode Nerd Font,Consolas, 'Courier New', monospace"
这时候你打开
starship.toml
就可以看到缺失的字体了 -
在
windows terminal
中配置字体在后续
windows terminal
配置中见
配置windows terminal
{
"$schema": "https://aka.ms/terminal-profiles-schema",
// "defaultProfile": "{61c54bbd-c2c6-5271-96e7-009a87ff44bf}",
"defaultProfile": "{574e775e-4f2a-5b96-ac1e-a2962a402336}",
"copyOnSelect": true,
"profiles": {
"defaults": {
"startingDirectory": "./",
"useAcrylic": true,
"acrylicOpacity": 0.8
},
"list": [{
"guid": "{61c54bbd-c2c6-5271-96e7-009a87ff44bf}",
"name": "Windows PowerShell",
"commandline": "powershell.exe",
"hidden": false,
"useAcrylic": true
},
{
"guid": "{0caa0dad-35be-5f56-a8ff-afceeeaa6101}",
"name": "cmd",
"commandline": "cmd.exe",
"hidden": false
},
{
"guid": "{2c4de342-38b7-51cf-b940-2309a097f518}",
"hidden": false,
"name": "Ubuntu",
"source": "Windows.Terminal.Wsl"
},
{
"guid": "{b453ae62-4e3d-5e58-b989-0a998ec441b8}",
"hidden": false,
"name": "Azure Cloud Shell",
"source": "Windows.Terminal.Azure"
},
// powershell 7
{
"guid": "{574e775e-4f2a-5b96-ac1e-a2962a402336}",
"hidden": false,
"name": "PowerShell",
"commandline": "C:/Program Files/PowerShell/7-preview/pwsh.exe -nologo",
"fontSize": 12,
// 字体配置
"fontFace": "FiraCode Nerd Font",
"historySize": 9001,
"padding": "5, 5, 20, 25",
"snapOnInput": true,
"colorScheme": "Andromeda",
"source": "Windows.Terminal.PowershellCore"
}
]
},
"schemes": [ {
"name": "Andromeda",
"black": "#000000",
"red": "#cd3131",
"green": "#05bc79",
"yellow": "#e5e512",
"blue": "#2472c8",
"purple": "#bc3fbc",
"cyan": "#0fa8cd",
"white": "#e5e5e5",
"brightBlack": "#666666",
"brightRed": "#cd3131",
"brightGreen": "#05bc79",
"brightYellow": "#e5e512",
"brightBlue": "#2472c8",
"brightPurple": "#bc3fbc",
"brightCyan": "#0fa8cd",
"brightWhite": "#e5e5e5",
"background": "#262a33",
"foreground": "#e5e5e5"
}],
"keybindings": []
}
这个时候打开windows terminal
windows terminal 加入系统右键
win+r
输入regedit找到计算机\HKEY_CLASSES_ROOT\Directory\Background\shell
新建项Terminal
(名字随便取)
选中
Terminal
,(默认)
为写入右键的文本Icon
为右键图标,自己找一个ico-
右键Terminal新建项
command
,在默认下写入值C:\Users\niwen\AppData\Local\Microsoft\WindowsApps\wt.exe
这里的
niwen
是我电脑用户的名称,你们自己找到wt.exe
然后把地址写上去就行
ok搞定现在试一下右键点击Terminal Here
有疑问加站长微信联系(非本文作者)