k-ocpw
Last Updated: February 25, 2016
·
5.881K
· creaktive
F93e90d4db9dc0eb3b5681c6fccfa0e2

Animated CPU chart in the Zsh prompt

Despite the fact that the rainbarf was originally intended to be used under tmux/screen, it actually works really well under the Zsh:

rainbarf + zsh

Note that the prompt itself (PS1) becomes animated, even when the shell is idle! To enable this hack, include the following lines in your ~/.zshrc (gist here):

# abort if already under tmux
[[ -n $TMUX_PANE ]] && return

# zsh-specific includes
zmodload -i zsh/datetime
zmodload -i zsh/stat

# place to store the chart
RAINBARF_OUT=~/.rainbarf.out
# update period, in seconds
TMOUT=30

# update the stored chart, avoiding running multiple rainbarf instances
rainbarf_update () {
    # check if non-existent or outdated
    if [[ \
        (! -e $RAINBARF_OUT) \
        || ($(stat +mtime $RAINBARF_OUT) -lt $(( $EPOCHSECONDS - $TMOUT ))) \
    ]]; then
        # rainbarf options should go to ~/.rainbarf.conf
        rainbarf --notmux > $RAINBARF_OUT
    fi
} 
rainbarf_update

# in-place prompt update hook
TRAPALRM () {
    rainbarf_update
    zle reset-prompt
}

# insert rainbarf chart into prompt
setopt PROMPT_SUBST
PS1="\$(cat $RAINBARF_OUT) $PS1"
Say Thanks
Respond

4 Responses
Add your response

6263

This is a completely useless thing. Dude, methinks that you've pimped-out your Zsh prompt just a mite to much perhaps?

over 1 year ago ·
6264
F93e90d4db9dc0eb3b5681c6fccfa0e2

@eddiesputz I'm absolutely sure it is useless. But it is cool, anyway :)

over 1 year ago ·
6268
1cecf680410c57a159a9b0717a198cfc

WHAT! You can animate your PS1 line!? I can already feel the ideas flooding into my brain.

over 1 year ago ·
6455
8b1f5ec314710be93ba93aaba7bda042

Heh, this is awesome. Thanks for sharing.

glances at his non-animated prompt

Yep, think it's yak shaving timeā€¦

over 1 year ago ·
Filed Under