WindowsTerminal 及 PowerShell 配置
安装
WindowsTerminal
- Microsoft Store 下载
- Github 下载 https://github.com/microsoft/terminal/releases
PowerShell
https://github.com/PowerShell/PowerShell/releases
Oh My Posh
管理员模式打开终端运行
1 2 3 4 5 6 7 8
| # 安装 oh-my-posh 包,让你的命令行更酷炫、优雅 Install-Module oh-my-posh -Scope CurrentUser // 这里是旧版安装方式,最新的oh-my-posh已取消,如果已经这么安装的建议卸载
# 卸载 oh-my-posh 包 Uninstall-Module oh-my-posh
# 安装最新版 oh-my-posh winget install JanDeDobbeleer.OhMyPosh -s winget // 下载完成后一定要重启 item,将工具全都关闭然后从新打开。
|
配置
安装 Powershell 插件 PSReadline、posh-git
管理员模式打开终端运行
1 2 3 4 5
| # 1. 安装 PSReadline 包,该插件可以让命令行很好用,类似 zsh Install-Module -Name PSReadLine -Scope CurrentUser -Force
# 2. 安装 posh-git 包,让你的 git 更好用 Install-Module posh-git -Scope CurrentUser
|
下载字体
下载 oh-my-posh 所需的字体库,这个需要再 oh-my-posh 下载完成之后运行
优化
浏览主题
-
打开终端输入
-
查看官网
https://ohmyposh.dev/docs/themes
更改主题
输入下列命令打开配置文件
修改配置文件,改为自己喜欢的主题后,保存退出,重启终端
1
| oh-my-posh init pwsh --config "$env:POSH_THEMES_PATH/主题名.omp.json" | Invoke-Expression
|
配置远程 SSH 连接
添加 SSH 配置
1.打开 Windows Terminal 设置,在左侧配置文件处,点击添加新配置文件,选择新建空配置文件

- 名称自定义,命令行更改为
1
| ssh root@服务器IP地址 -p 22 -o ServerAliveInterval=20
|

免密码登录
- 查看本机是否有 ssh 公钥,如果没有使用命令生成
1 2 3 4
| cat ~/.ssh/id_rsa.pub
ssh-keygen -t rsa -C
|
- 登录远程主机修改 authorized_keys 文件,将上述 windows 主机生成的 id_rsa.pub 添加进去,如果不存在使用上述 ssh-keygen 命令生成
1
| vi ~/.ssh/authorized_keys
|
美化远程主机终端
安装 Oh My Posh
1 2
| sudo wget https://ghproxy.net/https://github.com/JanDeDobbeleer/oh-my-posh/releases/download/v23.2.0/posh-linux-amd64 -O /usr/local/bin/oh-my-posh sudo chmod +x /usr/local/bin/oh-my-posh
|
安装主题
1 2 3 4 5
| mkdir ~/.poshthemes wget https://kkgithub.com/JanDeDobbeleer/oh-my-posh/releases/download/v23.2.0/themes.zip -O ~/.poshthemes/themes.zip unzip ~/.poshthemes/themes.zip -d ~/.poshthemes chmod u+rw ~/.poshthemes/*.omp.* rm ~/.poshthemes/themes.zip
|
应用 Oh My Posh
- 在远程主机运行如下命令确定 shell 的类型
1 2
| $ oh-my-posh get shell bash
|
- 参考官方文档https://ohmyposh.dev/docs/installation/prompt,针对不同shell类型有不同的应用方式。比如比较常见的bash,通常是在~/.bashrc文件的最下面添加一行
1
| eval "$(oh-my-posh init bash --config ~/.poshthemes/jandedobbeleer.omp.json)"
|
- 保存后重启 ssh 或者运行下列命令