- 参考链接1:https://blog.csdn.net/qq_39537898/article/details/117411132
- 参考链接2:https://sspai.com/post/59380 很有参考价值,介绍地很详细,常用的一些功能,个性化设置等等。
- 参考链接3:https://ohmyposh.dev/docs
- 参考链接4:https://blog.csdn.net/weixin_44490152/article/details/113854767 这是一个大神写的,清晰易懂,需要的话直接看这篇,如果觉得我这种更适合你,就继续往下看。
一、下载安装PowerShell7.X
powershell
官方网站:https://docs.microsoft.com/zh-cn/powershell/
下载链接:https://github.com/PowerShell/PowerShell/releases 下载 release
中的 msi
就可以了。
一直下一步就行。
注意:不要随便更改安装路径,否则无法识别!!!
二、在 PowerShell
中安装美化用的扩展包 posh-git & oh-my-posh
2.1 安装两个模块
以管理员身份运行PowerShell
,这里要强调下,是使用下载的 PowerShell
,而不是 Windows PowerShell
!否者下面安装的扩展包默认是在 Windows PowerShell
下面。
(2022-6-1 更新)
https://ohmyposh.dev/docs/installation/windows
https://lamirs.vercel.app/powershell%E7%BE%8E%E5%8C%96/
首先执行以下命令:
Set-ExecutionPolicy Bypass -Scope Process -Force; Invoke-Expression ((New-Object System.Net.WebClient).DownloadString('https://ohmyposh.dev/install.ps1'))
然后,重启 PowerShell
,以管理员的身份重新打开,执行以下命令:
Install-Module posh-git -Scope CurrentUser ## posh-git git美化管理包
Install-Module oh-my-posh -Scope CurrentUser ## oh-my-posh 基础美化工具包
2.2 添加配置
如果安装了VSCode
的直接使用code
命令,否者使用notepad
打开:
code $profile
notepad $profile
在配置文件中添加:
Import-Module posh-git ## 在当前打开的 PowerShell 终端中引入 posh-git(已安装,这里只是引入)
Import-Module oh-my-posh ## 同上,在当前打开的 PowerShell 终端中引入 oh-my-posh
Import-Module PSReadLine ## 这个工具主要做命令提示管理等操作,默认集成在了 PowerShell 中,不需要安装
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 ## 设置向下键为前向搜索历史记录
oh-my-posh init pwsh --config ~/Documents/PowerShell/themes/robbyrussel.omp.json | Invoke-Expression ## 设置主题,如果不喜欢robbyrussel这个主题,到oh-my-posh官方网站(https://ohmyposh.dev/docs/themes)找到自己喜欢的,然后换一下名字就可以
保存退出,一般重启就会自动引入和下载(如果本地没有下载主题配置文件)相应的文件:
官方的示例:https://ohmyposh.dev/docs/installation/customize
这里对应着 oh-my-posh
官方教程里面的下载说明,对应的实际命令是:
oh-my-posh init pwsh --config=‘配置json文件的路径’(可以直接引用官网地址,也可以直接下载到本地后,用绝对路径给出) | Invoke Expression
上面这个脚本文件对应的路径:
C:\Users\Username\Documents\PowerShell\Modules\oh-my-posh\7.60.0
实测中,发现有的主题字体显示不对,但是更换为 robbyrussel
主题,没有字体显示不整齐的现象,不想再继续折腾了,如果想要换其他主题,其实也比较简单,下载官方推荐的字体安装,基本就可以解决了。 有关字体问题,请看最后一节。
2.3 美化 conda & git
界面
使用 conda init powershell
之后,没有成功显示当前使用的虚拟环境。
解决方法:修改主题的配置文件!直接上 Everything
https://www.voidtools.com/downloads/ 进行搜索!找到 robbyrussel.omp.json
,双击打开,用下面的配置覆盖即可:
注意: 在主题
robbyrussel
的配置文件里面进行设置修改后才能显示当前使用的环境。
注意:Windows PowerShell
与PowerShell
使用的不是同一套配置文件,所以需要分别配置!
修改 PowerShell
对应的 robbyrussel
主题(这里要修改的原因是:官方提供的主题有 bug,无法显示当前的虚拟环境):
{
"$schema": "https://raw.githubusercontent.com/JanDeDobbeleer/oh-my-posh/main/themes/schema.json",
"blocks": [
{
"type": "prompt",
"alignment": "left",
"segments": [
{
"type": "python",
"style": "plain",
"foreground": "#E5E4E2",
"properties": {
"prefix": "(",
"postfix":") ",
"display_virtual_env": true,
"display_default": true,
"display_version": false,
"display_mode": "always"
}
},
{
"type": "text",
"style": "plain",
"foreground": "#98C379",
"properties": {
"prefix": "",
"text": "\u279C",
"postfix": ""
}
},
{
"type": "path",
"style": "plain",
"foreground": "#56B6C2",
"properties": {
"style": "folder"
}
},
{
"type": "git",
"style": "plain",
"foreground": "#D0666F",
"properties": {
"branch_icon": "",
"display_status": false,
"prefix": "<#5FAAE8>git:(</>",
"postfix": "<#5FAAE8>)</>"
}
},
{
"type": "exit",
"style": "plain",
"foreground": "#DCB977",
"properties": {
"prefix": "\u2717",
"display_exit_code": false
}
}
]
}
],
"final_space": true
}
conda init
之后重启terminal
才能生效。
GitBash
配置后,在 vscode
里面可能出现无法激活虚拟环境的错误,提示 conda init
然后重启,经过多次测试,发现这个提示毫无作用。
解决办法:https://blog.csdn.net/qq_40750972/article/details/123605334?spm=1001.2014.3001.5501
最终效果
到此,基本上就结束了。如果想要更加个性化的界面,可以参考官方的教程,论坛很活跃,一般有什么问题都能及时得到解决。
附录:settings.json下修改profiles进行自定义配置,自定义 Windows Terminal
的终端类型
"profiles": {
"defaults": {
"font": {
"face": "Consolas",
"size": 11
},
"useAcrylic": true,
"acrylicOpacity": 0.5, // 设置亚力克模糊度
"backgroundImage": "E:\\pics\\wallpapers\\221919.jpg", // 设置背景图片
"backgroundImageOpacity": 0.1
},
"list": [
{
"commandline": "E:/dev/envs/Git/bin/bash.exe --login -i",
"guid": "{227a404e-f2b1-47e9-a68b-b199c3a7fea3}",
"name": "GitBash"
},
{
"commandline": "pwsh.exe -nolog",
"guid": "{574e775e-4f2a-5b96-ac1e-a2962a402336}",
"hidden": false,
"name": "PowerShell",
"source": "Windows.Terminal.PowershellCore"
},
{
"commandline": "powershell.exe ssh 用户名@服务器地址",
"guid": "{026a9af4-ae5b-444e-8b3a-2045bd593817}",
"hidden": false,
"name": "AI Server"
}
]
},
需要修改的地方主要是:
backgroundImage
的路径;GitBash
的路径;- 最后一个自定义终端(
SSH
连接需要远程机器设置允许访问)服务器的登录用户名以及IP
地址。 guid
生成地址:https://www.uuidgenerator.net/version4
字体图标显示不全解决办法
- 官方主题使用说明:https://ohmyposh.dev/docs/themes
- 安装官方建议的字体:https://ohmyposh.dev/docs/config-fonts
Nerd Font
字体官方链接:https://www.nerdfonts.com/font-downloads 其中作者推荐的是MesloLGM NF
https://github.com/ryanoasis/nerd-fonts/releases/download/v2.1.0/Meslo.zip,将字体添加到settings.json
中就可以了。- 官方建议说明:Oh My Posh was designed to use Nerd Fonts. Nerd Fonts are popular fonts that are patched to include icons. We recommend Meslo LGM NF, but any Nerd Font should be compatible with the standard themes. To see the icons displayed in Oh My Posh, install a Nerd Font, and configure your terminal to use it.
下载完成后,右键选择为所有的用户安装:
安装完毕之后,可以在系统中看到已经安装好的 Meslo
字体:
将字体更改为以上 Meslo
中的一种即可,这里使用官方推荐的字体 MesloLGM NF
(图中第二行、第三列)。
最终效果:
最后,如果显卡驱动没有安装好,也是会造成字体显示不全的,这里附上 Inte
官方显卡驱动下载安装链接:https://www.intel.cn/content/www/cn/zh/support/intel-driver-support-assistant.html,具体安装好没有,可以到设备管理器里面进行查看,如果是以 Windows
开头的,说明要重新下载安装,这个也和 WIN11
透明效果不起作用有关。