之前写过一篇文章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