Windows Terminal&Git Bash美化

☪︎前言

♦️笔记本彻底报废了,没电脑又实在不行,买个N100小主机将就用着吧,将来换设备还能刷个软路由什么的👅

♦️等了两天终于到货了!装完系统修改注册表的时候发现系统自带的power shell界面是真的丑陋啊,于是决定用oh-my-posh来美化一下!

☪︎power shell 美化

  • 安装winget

一般power shell都自带了的,命令提示符下键入“winget”来运行 winget。若没安装可在微软商店搜索“应用安装程序”进行安装。

IMG_20230605_160639.jpg

  • JSON设置

打开JSON设置,定位到Defaults里添加:

使用亚克力效果:

1
2
"useAcrylic": true,
"acrylicOpacity": 0.2

设置背景:

1
2
"backgroundImage": "URL", 
"backgroundImageOpacity": 0.4

修改字体:

1
2
"fontFace": "JetBrainsMono Nerd Font Mono",
"fontSize": 14
  • 安装oh-my-posh

power shell输入命令

1
winget install JanDeDobbeleer.OhMyPosh -s winget

安装路径为*C:\Users\自己用户名\AppData\Local\Programs\oh-my-posh*

  • 预览全部主题

命令行键入可预览全部主题

1
Get-PoshThemes
  • 初始化并应用主题

安装了VScode的命令行输入code $PROFILE

打开配置脚本

在脚本输入oh-my-posh init pwsh --config $env:POSH_THEMES_PATH\montys.omp.json | Invoke-Expression保存即可

重启terminal生效

  • 若重启报错 无法加载文件C:\Users\anyae\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1,因为在此系统上禁止运行脚本

命令行运行set-executionpolicy remotesigned

  • 更换字体

主题生效后发现有很多乱码,更换一下字体即可解决,推荐使用JetBrains Mono字体

  • 去掉提示语

每次打开power shell都会显示提示语就很烦,直接打开JSON文件在power shell设置这里

"commandline": "%SystemRoot%\\System32\\WindowsPowerShell\\v1.0\\powershell.exe ***-NoLogo***",

加上 -Nologo就好了

☪︎Git Bash美化

  • 添加 Git Bash 到 Windows Terminal 的配置文件,使其可用 Tab 页打开
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
"profiles": 
{
"defaults": {},
"list":
[ # 找到此 list ,在里面添加如下
{
"guid": "{1cb09cbb-0365-91bf-c98f-d8d03c510274}",
"commandline": "%PROGRAMFILES%/git/usr/bin/bash.exe -i -l",
"icon": "%PROGRAMFILES%/Git/mingw64/share/git/git-for-windows.ico",
"name" : "Bash",
"startingDirectory" : "%USERPROFILE%",
"acrylicOpacity" : 0.75,
"closeOnExit" : true,
"colorScheme" : "Campbell",
"cursorColor" : "#FFFFFF",
"cursorShape" : "bar",
"fontFace" : "Consolas",
"fontSize" : 12,
"historySize" : 9001,
"padding" : "0, 0, 0, 0",
"snapOnInput" : true,
"useAcrylic" : true
},
  • 设置主题

将主题文件复制到$HOME 目录下

再在 ~/.profile 文件(没有则创建)添加命令,后执行 . ~/.profile 刷新,重启终端即可生效。

1
eval "$(oh-my-posh --init --shell bash --config ~/jandedobbeleer.omp.json)"
  • 乱码问题

安装 Meslo LGM NF 字体,避免乱码。

  • 安装图标库

使用命令安装图标库

1
Install-Module -Name Terminal-Icons -Repository PSGallery

profile里添加Import-Module -Name Terminal-Icons,使用.$profile加载

搞定!!!

参考文章:

Introduction | Oh My Posh

Windows 终端自定义提示符设置

Terminal终端美化(Oh My Posh) - 掘金