惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

爱范儿
爱范儿
博客园 - 【当耐特】
量子位
Engineering at Meta
Engineering at Meta
博客园_首页
大猫的无限游戏
大猫的无限游戏
IT之家
IT之家
V
Visual Studio Blog
小众软件
小众软件
阮一峰的网络日志
阮一峰的网络日志
美团技术团队
Jina AI
Jina AI
The Cloudflare Blog
T
Tailwind CSS Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
雷峰网
雷峰网
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
宝玉的分享
宝玉的分享
WordPress大学
WordPress大学
有赞技术团队
有赞技术团队
酷 壳 – CoolShell
酷 壳 – CoolShell
Last Week in AI
Last Week in AI
人人都是产品经理
人人都是产品经理
博客园 - 聂微东

Oh My Posh Blog

Studio, Native Git, and a Leaner Binary Oh My Posh Meets Claude Code: AI-Powered Terminal Prompts Deprecating the bash rprompt What's new #3 What idiot wrote this code? What's new #1
What's new #2
Jan De Dobbeleer · 2022-03-27 · via Oh My Posh Blog

Wouldn't have imagined doing part two in a week's time, but here we are again!

Features

CLI interface (also #2)

In the previous post I highlighted some changes in the CLI interface. Turns out I could make it even more straightforward. As Oh My Posh is a prompt generating utility, the prompt command doesn't make sense as that's implied. It has been removed, although it will keep working to not break existing functionality on upgrade.

Init

The following initialization:

oh-my-posh prompt init pwsh | Invoke-Expression

now becomes:

oh-my-posh init pwsh | Invoke-Expression

Debug

To debug Oh My Posh, you can simply use the debug command. It's smart enough to know your config so you don't have to specify the --config option.

Fish shell

We already supported fish shell for a while, but we stepped up the game. I started using fish as my primary shell, so obviously it couldn't stay behind. I suggest you also have a go at it, it's a very enjoyable experience.

But OK, what changed? We now support the following out-of-the-box:

It seems there's no support (yet) for a secondary prompt in fish, once that's available we can easily add that too. To enjoy all of this, upgrade to the latest and initialize fish by adding the following line to ~/.config/fish/config.fish:

oh-my-posh init fish | source

Transient prompt

Speaking of transient, it learned some new tricks. First, you can now use the .Code property to work with the last command's error code (if any) in the template. This can for example be used to color the transient prompt differently when the last command failed. That did imply we also needed support for color templates, as that wasn't possible just yet. Say no more, we now have a transient prompt that supports color templates.

"transient_prompt": {

"background": "p:yellow",

"background_templates": [

"{{ if gt .Code 0 }}p:red{{ end }}"

],

"foreground": "p:black",

"foreground_templates": [

"{{ if gt .Code 0 }}p:white{{ end }}"

],

"template": "<background,transparent>\ue0b6</> {{ .Folder }} <background,transparent>\ue0b0</><,transparent> </>"

}

Which produces the following result:

Terminal

Config version 2

Remember we did a migration to config version 1 in the beginning of the year? Well, we did a migration to version 2. Looking at Oh My Posh's architecture, the different prompts (transient, secondary, ...) were moving closer to the model used by segments. The only difference was that template wasn't a property, but a field of those prompts. As all segments now have template support, it was a no-brainer to align both models and do a migration to config version 2 so nobody would have any manual work in the process.

The following segment definition:

{

"background": "#9A348E",

"foreground": "#ffffff",

"leading_diamond": "\ue0b6",

"properties": {

"template": "{{ .UserName }} "

},

"style": "diamond",

"type": "session"

}

Will now be migrated to this for version 2:

{

"background": "#9A348E",

"foreground": "#ffffff",

"leading_diamond": "\ue0b6",

"style": "diamond",

"template": "{{ .UserName }} ",

"type": "session"

}

Go 1.18

Not something that impacts the end user directly, but maybe interesting to know is that Oh My Posh is now using go 1.18 by default. This brings obvious language improvements and a few new features we can play with. The most notable is generics, but it doesn't seem like we can benefit just yet as it's not yet supported for methods, and that's the main use-case for us.

Nonetheless, it's good to stay up-to-date, if you notice any quirks though, be sure to let us know!

That's it for this week, see you for the next one 🤞🏻

Keep that prompt posh everyone!