Using Go templates to customize the ruler #2084
Replies: 4 comments 7 replies
-
That is always the trade-off. I'd say we could add some example configurations to the wiki and mention that inside the built-in documentation.
This seems overblown just to have more status-bar customisation. |
Beta Was this translation helpful? Give feedback.
-
|
I think this sounds like a really cool idea, but if we go this route, why not go all the way and drop the ruler/stats/prompt wording and instead use templates for the top and bottom bars? That would feel more consistent and allow fuller customization. |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
|
You can use I use this to display the current cmd on-cd &{{
lf -remote "send $id tty-write \"\033]0;${PWD/#$HOME/~}\007\""
ref=""
if git rev-parse --is-inside-work-tree >/dev/null 2>&1; then
ref=$(git rev-parse --abbrev-ref HEAD 2>/dev/null)
if [ "$ref" = "HEAD" ]; then
ref=$(git rev-parse --short HEAD 2>/dev/null)
fi
fi
lf -remote "send $id :set user_ref '$ref'"
}}Inside my ruler, I have this: {{with $.UserOptions.ref}} {{printf "(%s)" .}}{{end -}} |
Beta Was this translation helpful? Give feedback.

Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
From discussion in #2057
Currently the ruler at the bottom can be customized using the
statfmtandrulerfmtoptions. While these options contain some level of flexibility, there are still some limitations when it comes to customization:statfmtcould not be drawn on the right side of the screen, and similarlyrulerfmtcomponents could not be drawn on the left side of the screen.The PR #2083 changes this to use Go templates instead to provide greater flexibility for customization, with the syntax being closer to a programming language instead of a format string. The tradeoff for the extra customizability is that the configuration is now more complex, which increases the barrier of entry for users.
To illustrate the history of the ruler configation:
ruleroption was added in Customizable statusline, df #1168, which allowed users to choose which fields to display and in which order:rulerfmtin Addrulerfmtoption for improved ruler customization #1386 to allow for custom formatting:rulerfile will look like this:Each step allows for greater flexibility in customization, but at the same time results in more complex syntax.
Another suggestion would be to use a scripting language like Lua for handling the configuration, but then that requires using some 3rd party library (as opposed to the standard library), and the implementation would be even more complex as the API has to bridge between Lua and Go. I am probably not interested in taking things that far.
Anyway this is an idea that I want to suggest, hopefully it is not too confusing for users.
Beta Was this translation helpful? Give feedback.
All reactions