Use Oh-my-posh prompt in Header
saumyajyoti opened this issue · comments
Please describe the problem you're trying to solve
Need to use oh-my-posh shell prompt as Yazi header similar to the Starship prompt
Would you be willing to contribute this feature?
- Yes, I'll give it a shot
Describe the solution you'd like
Need a similar script for OH-my-posh prompt like current Starship prompt plugin.
Additional context
No response
I've never used Oh-my-posh myself, but you should be able to refer to my answer about Starship in #767 (comment) and replace the starship prompt
with a corresponding Oh-my-posh command and it should work.
Thanks. I am able to use it for sync mode. Working code below. The async mode method does not work for Starship. So, not able to get it working for omp either.
return {
setup = function(st)
Header.cwd = function()
local cwd = cx.active.current.cwd
if st.cwd ~= cwd then
st.cwd, st.output = cwd, io.popen("oh-my-posh print primary"):read("*a"):gsub("^%s+", "")
end
return ui.Line.parse(st.output)
end
end,
}
I tried out the async version, and it works for me.
The only change I made based on the comments in that issue was:
- local output = Command("starship"):arg("prompt"):cwd(args[1]):env("STARSHIP_SHELL", ""):output()
+ local output = Command("oh-my-posh"):args({ "print", "primary" }):cwd(args[1]):output()
Please make sure you're using the latest Yazi v0.2.5 and have enabled it in your init.lua
:
require("oh-my-posh"):setup()
Yes, I am using latest main branch git code. Thanks for the snippet above. Somehow still async mode gives blank line for both the prompts for my system. Can I collect any debug log which can help here?
Can I collect any debug log which can help here?
Yeah you can, see https://yazi-rs.github.io/docs/plugins/overview#debugging
Thanks for your guidance. Somehow the async mode also started working now. Not sure what was the issue earlier.
Repo' link https://github.com/saumyajyoti-mukherjee/dotfiles/tree/main/AppData/Roaming/Yazi/config
Nice, glad to hear that!
Would you like to create a separate repo for it and add a README and LICENSE file? That way I can add it to the https://yazi-rs.github.io/docs/resources page so more people can use it.
Sure. I'll create and post here soon.
Created the repo' https://github.com/saumyajyoti/omp.yazi . But kept the sync mode default on as still seeing some issue with async update mode. I'll test more and change the behavior accordingly.
FYI, I am testing on Windows 11 setup with cmder as my console.
Thanks!
I am testing on Windows 11 setup with cmder as my console.
It might be related to path quoting on the Windows platform. Try forcing Unix quoting:
- ya.manager_emit("plugin", { st._name, args = ya.quote(tostring(cwd)) })
+ ya.manager_emit("plugin", { st._name, args = ya.quote(tostring(cwd), true) })
Needs the latest commit, 1f56203#diff-c10e812bd2c1fce1436f50a53aee0ce2976fc864917c5c81427bc74cc019f5eb
Thanks for the suggestion. It is working fine with Async mode now. Updated the repo'.