windows 终端美化
Windows Terminal
是 windows 一个终端工具,我们可以美化它来让自己赏心悦目。
通常电脑系统自带,如果没有的话可以通过 Microsoft Store
(微软商店),搜索 Windows Terminal
进行安装。
如果遇到了一些问题,还可以通过 Github
,搜索 Windows Terminal
进行安装。
美化
当我们能成功打开应用之后,就可以开始进行美化工作啦
首先安装 posh-git
,他可以对 git
命令进行一些支持
然后安装 oh-my-posh
,它提供了很多主题,让我们来尽心美化
// 1. 在终端输入以下命令,安装 posh-git
Install-Module posh-git
// 2. 在终端输入以下命令,安装 oh-my-posh
// oh-my-posh 的升级推荐我们使用 winget 去安装
// windows11 的同学自带 winget
// windows10 可以去 github 下载 winget
winget install oh-my-posh
// 3. 你可以输入以下命令,在终端查看所有主题样式
// 如果报错了,需要去配置一下你的环境变量变量哦
Get-PoshThemes
// 4. 输入以下命名,设置应用初始化
// 4.1 创建启动命令文本
if (!(Test-Path -Path $PROFILE )) { New-Item -Type File -Path $PROFILE -Force }
// 4.2 打开启动命令的文本,并修改
notepad $PROFILE
// 4.2.1 写入这一行,初始打开的时候会使用 `M365Princess` 主题样式,可以替换你喜欢的主题
// https://ohmyposh.dev/docs/themes
oh-my-posh init pwsh --config "$env:POSH_THEMES_PATH\M365Princess.omp.json" | Invoke-Expression
// 4.2.2 写入这一行的话,这个使用官网提供的默认主题样式
// oh-my-posh init pwsh | Invoke-Expression
/*
可能会出一些报错提示
无法加载文件 ... 因为在此系统上禁止运行脚本。
1. 输入 `get-ExecutionPolicy` 查看电脑执行脚本的策略,会显示 `Restricted`,表示任何安装脚本都受限制的
2. 输入 `set-ExecutionPolicy RemoteSigned` 修改为,有数字签名的不受限制
3. 再次输入 `get-ExecutionPolicy` 查看电脑执行脚本的策略,显示 `RemoteSigned` 即可成功
*/
如果出现乱码、问号?、小方框,是因为主题的一些特殊样式,需要我们下载安装字体来让他正常显示
我们还可以进入 M365Princess.omp.json
,去修改主题样式,做成自己喜欢的样子
{
"$schema": "https://raw.githubusercontent.com/JanDeDobbeleer/oh-my-posh/main/themes/schema.json",
"blocks": [
{
"alignment": "left",
"segments": [
{
"type": "text",
"style": "diamond",
"leading_diamond": "\ue0b6",
"foreground": "#ffffff",
"background": "#cc3802",
"template": "{{ if .Env.PNPPSHOST }} \uf8c5 {{ .Env.PNPPSHOST }} {{ end }}"
},
{
"type": "text",
"style": "powerline",
"foreground": "#ffffff",
"background": "#047e84",
"powerline_symbol": "\ue0b0",
"template": "{{ if .Env.PNPPSSITE }} \uf672 {{ .Env.PNPPSSITE }}{{ end }}"
},
{
"type": "text",
"style": "diamond",
"trailing_diamond": "\ue0b4",
"foreground": "#ffffff",
"background": "#047e84",
"template": "{{ if .Env.PNPPSSITE }}\u00A0{{ end }}"
}
],
"type": "rprompt"
},
{
"alignment": "left",
"segments": [
{
"background": "#DA627D",
"foreground": "#ffffff",
"powerline_symbol": "\ue0b0",
"properties": {
"style": "full"
},
"style": "powerline",
"template": " {{ .Path }} ",
"type": "path"
},
{
"background": "#FCA17D",
"foreground": "#ffffff",
"powerline_symbol": "\ue0b0",
"properties": {
"branch_icon": "",
"fetch_stash_count": true,
"fetch_status": false,
"fetch_upstream_icon": true
},
"style": "powerline",
"template": " \uf408 ({{ .UpstreamIcon }}{{ .HEAD }}{{ if gt .StashCount 0 }} \uf692 {{ .StashCount }}{{ end }}) ",
"type": "git"
},
{
"background": "#86BBD8",
"foreground": "#ffffff",
"powerline_symbol": "\ue0b0",
"style": "powerline",
"template": " \ue718 {{ if .PackageManagerIcon }}{{ .PackageManagerIcon }} {{ end }}{{ .Full }} ",
"type": "node"
},
{
"background": "#33658A",
"foreground": "#ffffff",
"properties": {
"time_format": "15:04"
},
"style": "diamond",
"template": " \u2665 {{ .CurrentDate | date .Format }} ",
"trailing_diamond": "\ue0b0",
"type": "time"
}
],
"type": "prompt"
}
],
"final_space": true,
"version": 2
}
一些我认为好看的颜色
// 好看的颜色
background-color: aquamarine;
background-color: #cc3802;
background-color: #9A348E; /* 用户名 颜色 */
background-color: #DA627D; /* 文件夹 颜色 */
background-color: #FCA17D; /* git 颜色 */
background-color: #86BBD8; /* node 颜色 */
background-color: #33658A; /* 时间 颜色 */
Tip:
windows powershell
和powershell
不一样powershell
更强大且支持跨端- 日常的使用
windows powershell
和powershell
区别不大
2022-05-01