简介
windows下面的CMD控制台很难用,也很丑,但是wndows后面出了个powershell,用着还是不错,但是还是丑,并且有些功能高效功能不具备,比如git分支显示,历史命令提示。
在windows下用了oh-my-zsh后,用着十分的舒服。所以在windows上寻找了一样的结局方案。利用powershell7打造属于windows的强劲终端
先上个效果图:
- Git分支显示
- 历史命令提示


终端选择
- Fluent Terminate(我的选择)
- Terminus
- Windows Terminal (微软应用商店)
- …
其实windows自带的也是可以的,不过用着总是不算那么舒服
下载Powershell7
去 PowerShell Release Page 下载安装即可
美化
本节就来改造下 PowerShell(以下简称 Posh)。
字体安装
需要配置PowerLine字体来显示一些特殊字符
# clone
git clone https://github.com/powerline/fonts.git --depth=1
# install
cd fonts
./install.sh
# clean-up a bit
cd ..
rm -rf fonts
再将终端字体设置为 Meslo LG S DZ for PowerLine
oh-my-posh
zsh 下有 oh-my-zsh,Posh 下也有 oh-my-posh 可以做到和 oh-my-zsh 一样的外观。
Install-Module posh-git -Scope CurrentUser
Install-Module oh-my-posh -Scope CurrentUser
Install-Module posh-docker -Scope CurrentUser
安装完后,我们还需要配置下 Posh 才能使其变成 oh-my-zsh 的样子。
首先在 Posh 中输入 $profile 并回车,Posh 会输出你当前使用的 Profile 文件地址,打开该文件(若没有就需要新建),在该文件中写入以下内容。
或者直接使用:
notepad $profile
编辑保存
写入:
Import-Module posh-git
Import-Module oh-my-posh
Set-Theme Paradox
# 单行显示,但是在我的IDEA下显示有问题 自测
#Set-Theme Agnoster
保存之后重启posh即可看到效果
命令提示
通过PSReadLine实现zsh-autosuggestions插件的功能。
安装:
Install-Module -Name PowerShellGet -Force
在主题配置文件后加入
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 # 设置向下键为前向搜索历史纪录
即可看到最开始简介时候的效果
配置Vim
- 下载vim: https://www.vim.org/download.php#pc
- 记住安装路径
- 编辑配置文件设置vim别名
执行:
notepad $profile
加入一行:
set-alias vim "D:\Program Files\Vim\vim82\vim.exe"

也可以把notepad++配置一下更加方便的编辑
set-alias open "C:\Program Files\Notepad++\notepad++.exe"
然后就可以通过open xx文件名打开文件了
配置代理
$http_proxy = "http://127.0.0.1:1080"
$socks5_proxy = "socks5://127.0.0.1:1080"
$env:http_proxy="$socks5_proxy"
$env:https_proxy="$socks5_proxy"
sudo
具体查看:https://github.com/gerardog/gsudo
通过scoop安装:
scoop install gsudo
安装之后就可以使用sudo了
在Idea中配置

填写自己PowerShell路径,加上nologo则不会打印开头的字体。

在VsCode中配置

选择默认终端为powershell7
配置字体无logo文字
{
"terminal.integrated.shell.windows": "C:\\Program Files\\PowerShell\\7\\pwsh.exe",
"terminal.integrated.fontFamily": "Meslo LG S DZ for PowerLine",
"terminal.integrated.shellArgs.windows": " -nologo",
}
其他
其实windows下还有wsl2,可以直接使用oh-my-zsh,但是我体验了一阵,发现如果在wsl2中编译windows下的文件十分缓慢,IO性能太差,不能日常,如果把项目放到wsl2中确实可以解决项目编译慢的问题,但是又会有其他一些问题,比如idea读取不到maven的子模块。坑就很多所以还是放弃了,也就偶尔用来使用windows环境了。