简易的个性化终端指南

基于 oh-my-posh3 的终端个性化简易指南

前言

默认 bash 难配置,zsh 功能强大但尺寸大易卡顿,fish 虽算是一个优良的 shell,但它并不遵循 POSIX。

并且由于 oh-my-posh 伴随了我两年多,所以最终选择了 oh-my-posh 来写个性化终端。实际上参照官方文档和示例来写一个配置并不难,我写完下面的示例文件也只用了一个多钟,所以最终能用上一个称手的终端还是挺舒服的。

适用于

  • oh-my-posh (bash)
  • windows powershell, linux most distro, macos

从示例开始

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
{
  "$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 寻找自己喜欢的提示符

分享一些我第一眼比较喜欢的

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
\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

CC BY-NC-SA 4.0 License