前言
默认 bash 难配置,zsh 功能强大但尺寸大易卡顿,fish 虽算是一个优良的 shell,但它并不遵循 POSIX。
并且由于 oh-my-posh 伴随了我两年多,所以最终选择了 oh-my-posh 来写个性化终端。实际上参照官方文档和示例来写一个配置并不难,我写完下面的示例文件也只用了一个多钟,所以最终能用上一个称手的终端还是挺舒服的。
适用于
- oh-my-posh (bash)
- windows powershell, linux most distro, macos
从示例开始
{
"$schema": "https://raw.githubusercontent.com/JanDeDobbeleer/oh-my-posh/main/themes/schema.json",
"blocks": [
{
"type": "newline"
},
{
"type": "rprompt",
"alignment": "right",
"segments": [
{
"type": "time",
"style": "plain",
"foreground": "#007ACC",
"properties": {
"postfix": ""
}
}
]
},
{
"type": "prompt",
"alignment": "left",
"segments": [
{
"type": "session",
"style": "plain",
"foreground": "#FFFFFF",
"properties": {
"user_info_separator": " <#b0bec5>on</> ",
"prefix": "",
"postfix": "",
"user_color": "#00e676",
"host_color": "#7c4dff"
}
},
{
"type": "os",
"style": "plain",
"foreground": "#26C6DA",
"properties": {
"macos": "\ue711",
"linux": "\ue712",
"wsl": "wsl",
"wsl_separator": " ",
"windows": "\ue70f",
"display_distro_name": false,
"alpine": "\uf300",
"arch": "\uf303",
"centos": "\uf304",
"debian": "\uf306",
"elementary": "\uf309",
"fedora": "\uf30a",
"gentoo": "\uf30d",
"manjaro": "\uf312",
"mint": "\uf30f",
"opensuse": "\uf314",
"raspbian": "\uf315",
"ubuntu": "\uf31c",
"postfix": " "
}
},
{
"type": "path",
"style": "powerline",
"foreground": "#b0bec5",
"background": "#2f2f2f",
"properties": {
"prefix": "",
"style": "mixed",
"home_icon": " \uf015 ",
"folder_separator_icon": "/"
}
},
{
"type": "git",
"style": "powerline",
"powerline_symbol": "\uE0B0",
"foreground": "#193549",
"background": "#95ffa4",
"properties": {
"display_stash_count": true,
"display_upstream_icon": true
}
},
{
"type": "command",
"style": "plain",
"foreground": "#b0bec5",
"properties": {
"shell": "bash",
"command": "git log --pretty=format:%cr -1 || date +%H:%m:%S"
}
}
]
},
{
"type": "newline"
},
{
"type": "prompt",
"alignment": "left",
"segments": [
{
"type": "root",
"style": "plain",
"foreground": "#FF0266",
"properties": {
"prefix": ""
}
},
{
"type": "python",
"style": "plain",
"foreground": "#F7CB3F",
"properties": {
"prefix": "py ",
"postfix": " ",
"display_mode": "text",
"display_version": true
}
},
{
"type": "exit",
"style": "plain",
"foreground": "#CB4B16"
},
{
"type": "text",
"style": "plain",
"foreground": "#FF0266",
"properties": {
"prefix": "",
"text": "\u09F8"
}
}
]
}
],
"final_space": true
}
字体
本人使用的是 JetBrainsMono Nerd Font Mono Regular
四位数的 unicode emoji 基本支持,五位数的没测过全部
如果需要使用五位数 unicode,可以去 Surrogate Pair Calculator etc. 转码
选择提示符
示例采用了 unicode \u09F8
可以去 Basic Latin — ✔️ ❤️ ★ Unicode Character Table 寻找自己喜欢的提示符
分享一些我第一眼比较喜欢的
\u29F3 形状
\uA538
\u09F8
\u09FB
\u2B9E 右箭头
\u27A5
\u25C6 菱形
\u261B right hand
\u2605 星星
\u2600 太阳
\u2BFD male
\u2C96 lambda
\u03BB
换行效果
示例在每行 prompt / 命令 之间加上了自动换行,这样可以使命令看起来不是那么密集
如果需要移除,请删除第一个 newline block
Command
这个 type 是用来执行 shell command,将输出追加到 segment 内
使用这个功能可以实现很多 DIY 效果
效果
忘了把 root 的提示符截图进去了,懒得加了
Referer
Docs: https://ohmyposh.dev/docs/configure
Schema: https://github.com/JanDeDobbeleer/oh-my-posh/blob/main/themes/schema.json