Why Byobu custom status notification code fail to show in color?
Matthew Barrera
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 ' | cut -d, -f2;tput sgr0` 2 Answers
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 --FF0000won'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".
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)
You need other color specifiers in screen (see Manpage of screen(1)). So first you should save the value in a variable:
AAPL=$(curl -s ' | cut -d, -f2)And in the second step you can output it with printf:
printf "\005{= b}%s%s\005{-}" "AAPL: " "$AAPL" 1