Update: Powerline Revisited
A while ago I came across Powerline for Vim, which is a plugin that shows a pretty status line in Vim. Needless to say, the default status line is awful, and I am too lazy to set up my own status line. Even if I did, my status line would probably not look as good as this. I grabbed vim-powerline feeling thankful, like every time I grab a Vim plugin.
I did notice, however, that Powerline for Vim has a big deprecation warning in the home page, pointing to Powerline as the replacement. Unfortunately, the new Powerline required Python 2.7, and I’d need to install something system-wide using Pip. Meh, that’s against my idea of having per-user configurations. Users should be able to configure their applications without having to obtain administrative access.
Recently, having some free time, I decided to hack Powerline eliminate the need to install it system-wide.
The Hack
It turned out, for Tmux and Vim no fix was needed. For Bash and Zsh the fix involves only a few lines of changes. I don’t really care about other things (yet?), so it was time to get my changes merged upstream. The process was simple: create a GitHub issue, then submit a pull request, but I did learn a few things:
- Bash sometimes will assign
-bash
to$0
, so$BASH_SOURCE
is a more reliable way to find the script file being executed. -
Zsh’s history expansion has modifiers that can be used to expand paths, convert lowercase to uppercase, quote, unquote and more. For example in Zsh
$0:A:h:h:h:h/scripts/powerline
is roughly equivalent to this piece in Bash:
$(dirname $(dirname $(dirname $(dirname $(realpath $BASH_SOURCE)))))
(eat that, Bash).
The default prompt doesn’t show the number of background tasks, so I added that. I also make the prompt left-only, as Bash does not support prompt on the right.
As usual, all settings, tweaks and hacks can be found in my dotfiles.
The Ugly
Now the pull request is still being reviewed, but Powerline is already powering a lot of the applications I use: Bash, Tmux, Vim and Zsh. The style looks great, but there are still caveats:
- Prompt generation time is too high. It’s still under an acceptable limit but
I can notice the delay before the prompt is printed. This becomes clear when
I hold down the
Enter
key. I guess this is a case of sacrificing performance for features. - Signals aren’t being handled correctly. Hitting
Ctrl+c
repeatedly would cause an exception. There is already an issue for this. Hopefully it will be resolved soon, or maybe I’ll find some time to hack it. - On some older machines that don’t have Python 2.7,
argparse
needs to be installed system-wide via Pip. I hate this, but at least it’s still better than installing some random thing from the Internet. Again, a fun hack waiting in store.
Questions or comments can go to Google+ :)