Skip to content

Windows PowerShell配置

Published: at 18:11

最近一直在使用Windows开发,所以需要配置一下终端。 在Windows store中安装Terminal,因为这个版本的界面看起来比较舒服,如下。

然后就是安装oh-my-posh & posh-git

Install-Module posh-git -Scope CurrentUser # posh-git

winget install JanDeDobbeleer.OhMyPosh # 新版oh-my-posh安装方式

可以在这里下载主题,推荐iterm2.omp.json主题

完成之后打开终端配置

code $PROFILE

输入下面代码

Import-Module posh-git # 引入 posh-git
Import-Module PSReadLine

oh-my-posh init pwsh --config <本机路>\iterm2.omp.json | Invoke-Expression

Set-PSReadLineOption -PredictionSource History # 设置预测文本来源为历史记录
 
Set-PSReadlineKeyHandler -Key Tab -Function Complete # 设置 Tab 键补全
Set-PSReadLineKeyHandler -Key "Ctrl+d" -Function MenuComplete # 设置 Ctrl+d 为菜单补全和 Intellisense
Set-PSReadLineKeyHandler -Key "Ctrl+z" -Function Undo # 设置 Ctrl+z 为撤销
Set-PSReadLineKeyHandler -Key UpArrow -Function HistorySearchBackward # 设置向上键为后向搜索历史记录
Set-PSReadLineKeyHandler -Key DownArrow -Function HistorySearchForward # 设置向下键为前向搜索历史纪录

配置完成之后可能会有乱码,需要安装字体,我安装的是FiraCode Nerd Font,下载解压之后,把ttf中的字体全选,然后右击为所有用户安装即可。 然后在terminal设置中打开JSON文件,在profiles下的defaults写入如下配置即可

"font": {
    "face": "FiraCode NF",
    "size": 14,
    "weight": "extra-light" //文字宽度,可设置加粗
},
"useAcrylic": true, // 启用毛玻璃
"colorScheme": "One Half Dark", //主题名字
"cursorShape": "vintage", //光标形状
"startingDirectory": "C://workspace//", //起始目录
"antialiasingMode": "cleartype" //消除文字锯齿