当前位置:   article > 正文

Windows Terminal的oh-my-posh配置方案_window oh my

window oh my

参考Tutorial: Set up a custom prompt for PowerShell or WSL with Oh My Posh

1 安装字体

NerdFonts字体下载
本人选择DejaVuSanMono Nerd Font作为个人喜好的字体。下载zip包后解压、全选安装即可。

2 安装oh-my-posh

  • 前往微软商城(Microsoft Store)搜索winget或应用安装程序,下载“winget”/“应用安装程序”。
  • 管理员权限的powershell中执行set-executionpolicy remotesigned,避免后续命令执行失败。
  • 在powershell中执行winget install XP8K0HKJFRXGCK。建议挂proxy下载,因为需要访问github仓库。

3 配置文件

  • powershell 执行notepad $PROFILE
    • 如果报错找不到文件,则执行echo $PROFILE找到文件路径,新建对应文件(通常为C:\Users\XXX\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1)
  • $PROFILE文件中添加oh-my-posh init pwsh --config "$env:POSH_THEMES_PATH\XXX.omp.json" | Invoke-Expression ,注意XXX需要替换为你想要使用的主题。可访问oh-my-posh主题查看所有主题,或使用本人自改后的主题(如下,注意上述命令中json路径需要更改为自改主题路径)。

4 最后

在windows terminal的“设置=>默认值=>外观=>字体”中将字体更改为之前安装的Nerd字体。
如果想在powershell启动时不出现乱七八糟的信息,可以在“设置=>windows powershell=>命令行”中命令末尾添加-nologo即可。

{
    "$schema": "https://raw.githubusercontent.com/JanDeDobbeleer/oh-my-posh/main/themes/schema.json",
    "blocks": [
      {
        "alignment": "left",
        "segments": [
          {
            "foreground": "#FFBD00",
            "style": "plain",
            "template": "{{ .UserName }}'s ",
            "type": "session"
          },
          {
            "foreground": "#00C6F7",
            "properties": {
              "style": "folder"
            },
            "style": "plain",
            "template": "{{ .Path }}/ ",
            "type": "path"
          },
          {
            "foreground": "#F62F2E",
            "properties": {
              "fetch_status": true
            },
            "style": "plain",
            "template": "<#ffffff>on</> {{ .HEAD }}{{if .BranchStatus }} {{ .BranchStatus }}{{ end }}{{ if .Working.Changed }} \uf044 {{ .Working.String }}{{ end }}{{ if and (.Working.Changed) (.Staging.Changed) }} |{{ end }}{{ if .Staging.Changed }} \uf046 {{ .Staging.String }}{{ end }} ",
            "type": "git"
          },
          {
            "foreground": "#98C379",
            "properties": {
              "fetch_version": true
            },
            "style": "plain",
            "template": " \ue781 {{ if .PackageManagerIcon }}{{ .PackageManagerIcon }} {{ end }}{{ .Full }} ",
            "type": "node"
          },
          {
            "foreground": "#FFDE57",
            "properties": {
              "fetch_version": true
            },
            "style": "powerline",
            "template": " \ue235 {{ if .Error }}{{ .Error }}{{ else }}{{ .Venv }} {{ .Full }}{{ end }} ",
            "type": "python"
          },
          {
            "foreground": "#00acd7",
            "properties": {
              "fetch_version": true
            },
            "style": "powerline",
            "template": " \ue627 {{ if .Error }}{{ .Error }}{{ else }}{{ .Full }}{{ end }} ",
            "type": "go"
          }
        ],
        "type": "prompt"
      },
      {
        "alignment": "right",
        "segments": [
          {
            "foreground": "#85C980",
            "style": "diamond",
            "template": "RAM:{{ (div ((sub .PhysicalTotalMemory .PhysicalFreeMemory)|float64) 1000000000.0) }}/{{ (div .PhysicalTotalMemory 1000000000.0) }}GB ",
            "trailing_diamond": " ",
            "type": "sysinfo"
          },
          {
            "foreground": "#ffffff",
            "leading_diamond": "\u250b",
            "properties": {
              "style": "galvestonms",
              "threshold": 0
            },
            "style": "diamond",
            "template": " {{ .FormattedMs }} ",
            "type": "executiontime"
          }
        ],
        "type": "prompt"
      },
      {
        "alignment": "left",
        "newline": true,
        "segments": [
          {
            "foreground": "#FFBD00",
            "style": "plain",
            "template": "\u2b9e ",
            "type": "text"
          }
        ],
        "type": "prompt"
      }
    ],
    "final_space": true,
    "version": 2
  }
  • 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
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小丑西瓜9/article/detail/709506
推荐阅读
相关标签
  

闽ICP备14008679号