本文旨在快速让你进行美化,少踩一些坑,原文出自我的博客:prettier-windows-terminal-with-oh-my-posh

为了同 iterm2 下的 oh-my-zsh 保持基本一致,博主用的是 aliens 主题+一些自定义配置调整,最终效果如下,你也可以根据自己需要进行细调

  • 如果你闲麻烦,或者想跟我用一样的,文末会给出主题配置,直接拿去用即可。
  • 效果图:

版本说明:

  • 本文撰写时:

    • oh-my-posh 版本为 v7.87.0
    • powershell 的版本为 7.2.3,(最新为 7.2.4)
    • OS:win10,21H1,19043.1706

注意事项:

1. 安装时请关闭杀毒软件、各类管家,否则写入注册表时会报错。

2. 有条件的请挂代理,因为源文件在 git 上。

3. 全程在 powershell ,管理员模式 下进行。

安装 windows terminal:

可直接在 microsoft store 中搜索安装。这里不赘述。

安装 powershell@latest

官网:https://docs.microsoft.com/zh-cn/powershell/scripting/install/installing-powershell-on-windows?view=powershell-7.2

  • 你的系统中,powershell 可能不是新版,一样弄,强烈建议使用最新版本的 powershell。

    • 因为新版会增加不少工具包,如 Test-Path 等,可以省去不少自己去各类安装包的麻烦。也可以减少、避免不必要的安装错误。

安装 gsudo

如其名,为了在 windows 下使用 sudo 命令,需要安装该包。

git 地址:https://gerardog.github.io/gsudo/docs/install

可以直接在 powershell 中执行以下命令进行安装:

winget install gerardog.gsudo
  • 会自动注册到 path,所以你可以直接在命令行中全局使用:
# 示例:以管理员身份启动 powershell
gsudo powershell.exe

如果你觉得 gsudo 不够直观,希望用 sudo,可以通过以下方式重命名:

Set-Alias 'sudo' 'gsudo'

安装 oh-my-posh

官方:https://ohmyposh.dev/

git 地址:https://github.com/jandedobbeleer/oh-my-posh

winget install oh-my-posh
  • 以上命令会安装 oh-my-posh.exe 以及最新的主题。

安装 Nerd Fonts

oh-my-posh 的不少主题都是依赖于该字体,否则部分 icon 会乱码,建议安装。

windows terminal 配置

启动 shell 设置为 powershell 7

以管理员权限启动 shell

在 windows terminal 的设置中,打开JSON文件:



编辑配置:

  • 只要安装了 powershell 7,默认情况下 pwsh 就会指向 powershell 7。
  • 如果你没有给 gsudo 添加 sudo 别名的话,这里用 gsudo

设置 powershell 7 字体为 Nerd fonts

配置启动时加载 oh-my-posh

创建 powershell 配置文件:

if (!(Test-Path -Path $PROFILE )) { New-Item -Type File -Path $PROFILE -Force }

用记事本打开配置文件

notepad $PROFILE

在记事本中录入以下指令

oh-my-posh init pwsh --config ~/.leon.omp.theme.json | Invoke-Expression
  • 每次启动 shell 时 ,会先执行以上命令以加载主题等配置。
  • 其中 "--config ~/.leon.omp.theme.json" 是你的文件和所在路径,文末我会放出我的配置。
  • 你可以在 这里 找到不同的主题。

快捷键设置:

习惯了 iterm2 中 CMD+D,SHIFT+CMD+D 来拆分窗口,很庆幸 windows terminal 已经提供了快捷键修改,且针对的就是拆分窗口,直接设置即可,如下:

.leon.omp.theme.json

{
"$schema": "https://raw.githubusercontent.com/JanDeDobbeleer/oh-my-posh/main/themes/schema.json",
"blocks": [
{
"alignment": "left",
"segments": [
{
"background": "#61AFEF",
"foreground": "#ffffff",
"leading_diamond": "\ue0b6",
"style": "diamond",
"template": "{{ .HostName }} ",
"trailing_diamond": "\ue0b0",
"type": "session"
},
{
"background": "#C678DD",
"foreground": "#ffffff",
"powerline_symbol": "\ue0b0",
"properties": {
"style": "full"
},
"style": "powerline",
"template": " {{ .Path }} ",
"type": "path"
},
{
"background": "#95ffa4",
"foreground": "#193549",
"powerline_symbol": "\ue0b0",
"style": "powerline",
"template": " {{ .HEAD }} ",
"type": "git"
},
{
"background": "#FF6471",
"foreground": "#ffffff",
"leading_diamond": "<transparent,background>\ue0b0</>",
"style": "diamond",
"template": " {{ if .Error }}{{ .Error }}{{ else }}{{ if .Venv }}{{ .Venv }} {{ end }}{{ .Full }}{{ end }} ",
"trailing_diamond": "\ue0b4",
"type": "python"
}
],
"type": "prompt"
}
],
"final_space": true,
"version": 2
}
  • 属性说明你可以从 这里 了解。

使用 oh-my-posh 美化 windows terminal,让其接近oh-my-zsh的更多相关文章

  1. 黑科技抢先尝(续) - Windows terminal中WSL Linux 终端的极简美化指南

    目录 修改默认源,为apt-get安装提速 安装python 和 python pip 安装 zsh 安装powerline-font中的特定字体 安装powerline-shell 修改~目录下的配 ...

  2. Windows Terminal安装并美化

    介绍 Windows Teminal是一款新式.快速.高效.强大的终端应用程序,适用于命令行工具.命令提示符.PowerShell.WSL(Linux子系统)等等的Shell用户,主要功能包括多选项卡 ...

  3. 黑科技抢先尝(续2) - Windows terminal中Powershell Tab的极简美化指南

    目录 安装python 安装git 安装powerline字体 主题定制 安装oh-my-posh 查看策略组的执行权限 使用choco 安装终端模拟器 - ConEmu 优化 PowerShell ...

  4. Windows Terminal 安装及美化

    windows terminal 是今年微软Build大会上推出的一款的全新终端,用来代替cmder之类的第三方终端.具有亚克力透明.多标签.Unicode支持(中文,Emoji).自带等宽字体等这些 ...

  5. 深入浅出,遇见Windows Terminal(Windows终端器),体验及美化新一代终端神器

    Windows Terminal 简介 Windows Terminal is a new, modern, feature-rich, productive terminal application ...

  6. Windows Terminal 美化教程

    Windows Terminal 美化教程 1.安装Windows Terminal 在微软商店搜索Windows Terminal下载即可 2.安装相应的插件 使用管理员权限打开Windows Te ...

  7. 是时候扔掉cmder, 换上Windows Terminal

    作为一个Windows的长期用户,一直没有给款好用的终端,知道遇到了 cmder,它拯救一个习惯用Windows敲shell命令的人. 不用跟我安利macOS真香!公司上班一直用macOS,一方面确实 ...

  8. Windows10上安装Linux子系统(WSL2,Ubuntu),配合Windows Terminal使用

    Linux 的 Windows 子系统可让开发人员按原样运行 GNU/Linux 环境 - 包括大多数命令行工具.实用工具和应用程序 - 且不会产生传统虚拟机或双启动设置开销. WSL 说白了安装Li ...

  9. 终于等到你!微软正式上线 Windows Terminal 预览版

    前一段时间,一直在知乎.技术社区收到技术小伙伴们的终极拷问:微软Build 大会上提到的**6月中旬**要上Windows store 的 Windows Terminal 到底啥时候可以用到呀? 有 ...

随机推荐

  1. PCB常用低速、高速板材参数性能(2)

  2. [开源] 分享自己用的 GitHub 分组管理工具.

    CODELF 的 GitHub Star 管理工具, 简洁快速,从开发者角度考虑,用完就走,不给开发者更多的管理负担. http://unbug.github.io/codelf/ 这个工具目前在 G ...

  3. 大数据学习之路之ambari的安装

    之前按照正常方式安装的hbase不能插入数据 所以今天来尝试下ambari能不能行 已经打了快照 如果不能还能恢复之前的样子

  4. Unable to configure HTTPS endpoint. No server certificate was specified, and the default developer certificate could not be found 解决办法

    问题 每次vs重启都提示安装证书,即使执行dotnet dev-certs https --clean,dotnet dev-certs https -t然后重启vs也不行. 环境 win10, vs ...

  5. 硬件vendor id查询对照列表

    Hex-ID Vendor Name003D Lockheed Martin Corp0E11 Compaq1000 Symbios Logic Inc.1001 KOLTER ELECTRONIC1 ...

  6. 利用js获取不同页面间跳转需要传递的参数

    获取参数的js函数如下: function GetQueryValue(queryName) { var query = decodeURI(window.location.search.substr ...

  7. Ubu18.0-NVIDIA显卡驱动重装

    //图片仅供参考,请勿代入 问题情况:电脑装了双系统,WIN10+Ubu,Ubu分辨率不稳定,经常发生变化 显卡型号:打开设备管理器进行查看 解决方法:重装NVIDIA显卡驱动 1.去英伟达官网下载自 ...

  8. 在定义C++, C通用接口函数时让C++接口支持默认参数

    在SOUI4的开发中,所有SOUI核心对象都采用了一种类似COM接口的技术来导出接口. 这所以采用这种方案,主要目的是为了让SOUI4支持C语言调用,扩展SOUI的使用场景. 众所周知,C++函数的参 ...

  9. 实现深拷贝还在用JSON.parse(JSON.stringify(obj))?带你用JS实现一个完整版深拷贝函数

    使用JavaScript实现深拷贝 1.JSON序列化实现深拷贝 在JS中,想要对某一个对象(引用类型)进行一次简单的深拷贝,可以使用JSON提供给我们的两个方法. JSON.stringfy():可 ...

  10. innodb源码解析 - mem0_.c - 基本内存管理

    The basic element of the memory management is called a memoryheap. A memory heap is conceptually ast ...