Ubuntu – Why Byobu custom status notification code fail to show in color

bashbyobuscriptsserver

The code below runs well in Bash and shows text with proper green background color but when I add it to the ~/.byobu/bin/ folder it shows the escape characters instead. Something like [42m[1mAAPL:30.345 (B[m

#!/bin/sh
echo `tput setab 2;tput bold`AAPL:`curl -s 'http://download.finance.yahoo.com/d/quotes.csv?s=AAPL&f=sl1d1t1c1ohgv&e=.csv' | cut -d, -f2;tput sgr0`

Best Answer

If using the tmux backend for byobu, you will need to use a different format for color codes. Luckily, it's less complicated than the screen format.

To set colors, use #[<color and attribute codes>]. Examples:

  • #[default]: restore default colors (use at the end of your custom status).
  • #[fg=red]: set the foreground color to red.
  • #[fg=#ff0000]: set the foreground color to #ff0000. Only accepts lowercase -- FF0000 won't work.
  • #[bg=black]: makes the background black.
  • #[fg=bold]: makes text bold. See below for more.
  • #[reverse]: swaps foreground/background colors.

You can combine them, e.g. #[fg=white,bold,bg=black].

Named colors: black, red, green, yellow, blue, magenta, cyan, white, black, brightblack, brightred, brightgreen, brightyellow, brightblue, brightmagenta, brightcyan, brightwhite

Attributes: dim, underscore, bold, reverse, standout, blinking, hidden, italics

You can also use the environment variables $BYOBU_LIGHT, $BYOBU_DARK, $BYOBU_ACCENT, and $BYOBU_HIGHLIGHT as colors.


To play with this, create a file, ~/.byobu/bin/1_hello with the following contents, and make it executable.

#!/bin/sh
echo "#[reverse]Hello world#[default]"

This should create a black-on-white status notification that says "Hello world".


A few custom status notifications for byobu

Here are two example custom status bar components, and the codes that produce them:

  • #[fg=#aa77cc,bg=#222222] @XXX.XX #[default]
  • #[fg=white,bg=black] ✉ ️X #[default]

This information will probably only work if you're using tmux and a color-enabled shell, though :)


(Sources: /usr/lib/byobu/include/colors, /usr/lib/byobu/include/shutil)

Related Question