Skip to content

Windows Terminal 设置与美化

Published: at 12:40

迁移自
Windows Terminal 添加到右键菜单 - J.晒太阳的猫 - 博客园
Windows Terminal-CSDN博客

🍉 安装

Windows 终端概述 | Microsoft Learn
microsoft/terminal - github

安装方式,可以使用 wingetchocoscoopMicrosoft Store 等方式安装,具体可以参考 github readme 中的安装说明。

安装完成之后,会在 C:\Users\你的名字\AppData\Local\Microsoft\WindowsApps 中,创建一个 wt.exe 的软链接(但看起来又不像是软链接,使用 attrib 找不到目标)。

WindowsApps 这个目录是在环境变量中的,所以可以直接在命令行中使用 wt 命令打开 Windows Terminal。

Terminal window
wt --help

添加右键菜单 - 在当前目录打开

lextm/windowsterminal-shell: Install/uninstall scripts for Windows Terminal context menu items

Terminal window
# 打开指定目录
wt -d %USERPROFILE%
wt -d .

🍉 ohmyposh 美化

https://ohmyposh.dev/docs/installation/windows

Terminal window
# 安装 oh-my-posh, powershell
Set-ExecutionPolicy Bypass -Scope Process -Force; Invoke-Expression ((New-Object System.Net.WebClient).DownloadString('https://ohmyposh.dev/install.ps1'))

一般会自动添加,重启终端即可。如果没有,则进行手动添加。

Terminal window
$env:Path += ";C:\Users\user\AppData\Local\Programs\oh-my-posh\bin"

Fonts | Oh My Posh

Terminal window
oh-my-posh font install meslo

不过,发现这样安装的字体,过段时间可能会失效。如果遇到了,可以直接下载字体文件,然后全部安装到系统中。

字体下载:Nerd Fonts - Iconic font aggregator, glyphs/icons collection, & fonts patcher

下载一个你喜欢的字体,通常是一个安装包,里面有批量安装的脚本,直接运行即可。

使用如下方式配置 Windows Terminal 的字体

"profiles":
{
"defaults":{
"startingDirectory": ".",
"font":{
"face": "MesloLGM Nerd Font"
}
}
}

这里有主题效果:Themes | Oh My Posh

Customize | Oh My Posh
Change your prompt | Oh My Posh

主题的配置文件,在 C:\Users\jgrass\AppData\Local\Programs\oh-my-posh\themes 目录中。

如果是其它主题,可以使用在线链接,也可以将 json 文件下载到 themes 文件夹。

比如我看中了 ys 这个主题,可以使用如下方式(powershell)进行配置:

以 powershell 为例,就是修改其启动配置文件

Terminal window
notepad $PROFILE
# 如果说没有找到文件,则新建一个:
New-Item -Path $PROFILE -Type File -Force

Terminal window
oh-my-posh init pwsh --config "$env:POSH_THEMES_PATH/ys.omp.json" | Invoke-Expression

ys.omp.json 为具体的配置文件名称,可以在 env:POSH_THEMES_PATH 目录中找到,如果没有,使用 Get-PoshThemes 命令获取

Themes | Oh My Posh

Terminal window
oh-my-posh upgrade

🍉 设置 powershell 的默认启动目录

如何在 Windows 终端中更改默认目录|windows|应用程序|ubuntu|shell|powershell_网易订阅

"startingDirectory": "%USERPROFILE%\\Desktop"

我的配置,将默认目录设置为桌面,但是单独的配置设置为 . ,即当前目录。 这样默认打开是在桌面,但是如果是在某个指令目录打开 windows terminal 之后,再添加新的 TAB,就是在当前目录。

"profiles":
{
"defaults":
{
"font":
{
"face": "MesloLGM Nerd Font"
},
"startingDirectory": "%USERPROFILE%\\Desktop",
"backgroundImage": "C:\\Users\\jgrass\\Pictures\\Wilderness_Road_Dawn_Shooting_star_United_States.jpg",
"backgroundImageOpacity": 0.8,
},
"list":
[
{
"commandline": "%SystemRoot%\\System32\\WindowsPowerShell\\v1.0\\powershell.exe",
"guid": "{61c54bbd-c2c6-5271-96e7-009a87ff44bf}",
"hidden": false,
"name": "Windows PowerShell",
"startingDirectory": "."
},
{
"commandline": "%SystemRoot%\\System32\\cmd.exe",
"guid": "{0caa0dad-35be-5f56-a8ff-afceeeaa6101}",
"hidden": false,
"name": "\u547d\u4ee4\u63d0\u793a\u7b26",
"startingDirectory": "."
}
]
}

🍉 设置背景

Windows 终端外观配置文件设置 | Microsoft Learn

https://www.10wallpaper.com/view/Wilderness_Road_Dawn_Shooting_star_United_States_5K.html
https://www.10wallpaper.com/view/Golden_Glare_Lines_Dark_Abstract_Design.html

🍉 常用命令

Terminal window
# 编辑配置文件
notepad $PROFILE
# 使用 VS Code 编辑配置文件
code $PROFILE
# 应用配置文件
. $PROFILE

🍉 PowerShell 7

从 Windows PowerShell 5.1 迁移到 PowerShell 7 - PowerShell | Microsoft Learn
Windows PowerShell 5.1 与 PowerShell 7.x 之间的差异 - PowerShell | Microsoft Learn
Installing PowerShell on Windows - PowerShell | Microsoft Learn

推荐是最新的 PowerShell 7

查看 powershell 版本,使用 $host 命令查看

如果要修改 Windows Ternimal 的默认终端,可以修改 defaultProfile 为对应终端的 guid

🍉 参考

Windows terminal美化工具Oh-My-Posh-腾讯云开发者社区-腾讯云


原文链接: https://blog.jgrass.cc/posts/windows-terminal/

本作品采用 「署名 4.0 国际」 许可协议进行许可,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文链接。