Skip to content

Instantly share code, notes, and snippets.

@creaktive
Last active January 27, 2023 18:44
Show Gist options
  • Star 13 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save creaktive/5528983 to your computer and use it in GitHub Desktop.
Save creaktive/5528983 to your computer and use it in GitHub Desktop.
rainbarf sans tmux (to enable, "source rainbarf.zsh", under zsh)
# 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"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment