256 colours in tmux
I’m decorating my tmux setup and needed to confirm colour numbers for some elements of the interface. Turns out, it’s simple enough to show all the possible colours with a 1-liner in your favourite Unix shell – bash shell in my case.
I’ll explain how this works in full detail sometime in a separate post, but for now will just give you an example and show how it works:
Colour control in BASH
So, in this example, this is how we achieve colorized text output:
Here’s how we get the colours now: we create a loop from 1 until 255 (0 will be black) and then use the ESC syntax changing colour to $COLOR variable value. We then output the $COLOR value which will be a number:
Here’s how running this will look in a propertly configured 256-color terminal:
BASH - show colour codes
Here’s the same 1-liner converted into proper script for better portability and readability:
If you save this as bash-256-colours.sh and chmod a+rx bash-256-colours.sh, you can now run it every time you want to refresh your memory or pick different colours for some use.