Today a user on IRC wondered how hard it would be to indicate the current mode of zsh's vi keyboard mode in grml's new prompt-theme.

The prompt theme is designed to not only be configurable, but also to be extensible with custom information. The theme is not the issue with this request. The issue is to get solid information about the current state of zsh's vi-mode, with ordinary keymap changes, signal handling, recognition of minibuffers and override modes...

Since I use vi-mode in my zsh setup, I did all that a while back (CODE: You may want to take a look at the CONFIGURATION section, especially `zle_use_ctrl_d', which you may want to set to "no" if you like to use ESC like you'd expect in vi). Which means that the only question that remains is how to actually perform the integration.

Turns out, that this is rather easy. Suppose you copied the code that's linked from my old blog post to ~/.zshrc.vi-mode. Let's do the integration in ~/.zshrc.local, which is a file that grml's zshrc loads after all its own code ran. The integration can be done in three lines of code then:

source ~/.zshrc.vi-mode
grml_theme_add_token vi-mode '%1v' '%K{blue}%F{white}(' ')%f%k '
zstyle ':prompt:grml:left:setup' items vi-mode rc change-root \
                                       user at host path vcs percent

And here's how that looks:

vi-mode integration with grml's new prompt theme

I'm kind of glad, we rewrote our prompt code to make things like this possible, clean and fairly easy. :)

Posted Tue 05 Aug 2014 13:47:03 CEST Tags: