181

I'm trying to set something to gray, but can't figure out how. The only bit of info in the man page about colors I can find is:

message-bg colour
  Set status line message background colour, where colour is one of:
  black, red, green, yellow, blue, magenta, cyan, white, colour0 to
  colour255 from the 256-colour palette, or default.

I also found a blog post which iterates through colors, but I can't quite grok it, and don't want to sit at the terminal all day guessing color numbers until one works.

Lawrence
  • 1,957
  • 3
  • 12
  • 10

7 Answers7

268

You can get a list with this bash snippet:

for i in {0..255}; do
    printf "\x1b[38;5;${i}mcolour${i}\x1b[0m\n"
done

Then use colourxxx with tmux.

cYrus
  • 21,379
  • 8
  • 74
  • 79
144

I found this image to be enlightening.

enter image description here

Eddie Parker
  • 2,824
  • 8
  • 30
  • 37
  • 38
    You can create it with `for i in {0..255}; do printf "\x1b[38;5;${i}mcolor%-5i\x1b[0m" $i ; if ! (( ($i + 1 ) % 8 )); then echo ; fi ; done` – 12431234123412341234123 Oct 04 '17 at 11:10
  • An alternative output that groups the colors after `colour15` is generated with `for i in {0..255}; do printf "\x1b[38;5;${i}mcolor%-5i\x1b[0m" $i ; if ! (( ($i - 3) % 6 )); then echo ; fi ; done`. – G-Wiz Feb 08 '23 at 22:48
25

In Subversion (what will be tmux 1.5) you can also use #abcdef hex-style colours which are mapped to the nearest 256 colour palette entry. You need quotes as it's treated as a string, whereas regular color names are treated as named constants. Also note that 3-letter shorthand (#f00) is invalid.

Example:

set pane-active-border-bg red # no quotes for name
set pane-active-border-bg "#ff0000" # quotes for rgb
mahemoff
  • 1,023
  • 1
  • 11
  • 16
Bob
  • 1,446
  • 13
  • 6
19

Before tmux 3.2 (released in April 2021), tmux only supported the international (British) spelling for the 256 colour palette, e.g.

"colour121"

as opposed to the American spelling that drops the u

"color121"

If you're using tmux 3.2 or later, you can spell it either way.

Joe Fortier
  • 291
  • 2
  • 3
8

Building up on @cYrus' answer, I wrote a script to break the output of the colors into N number of columns, where N is the first argument

# colors.sh

#!/bin/bash
if [ -z $1 ]; then
    BREAK=4
else
    BREAK=$1
fi
for i in {0..255} ; do
    printf "\x1b[38;5;${i}mcolour${i} \t"
    if [ $(( i % $BREAK )) -eq $(($BREAK-1)) ] ; then
        printf "\n"
    fi
done

Try it by saving it into a file called colors.sh, then ./colors.sh 4

Don't forget to chmod +x colors.sh first.

airstrike
  • 695
  • 7
  • 12
  • 4
    Script [show-256-colors.sh](https://gist.github.com/ivanbrennan/8ce10a851851e5f04728d8da900ef1c5) can be useful to show background colors as well. – Maxim Suslov Aug 02 '18 at 01:47
  • 1
    You ought to default it to say, at least 4 columns, to distinguish it from the origin script. – dbkeys Aug 26 '19 at 13:28
7

I've been using the xterm-color-table.vim script. Any 256 color terminal color table will work.

zero2cx
  • 641
  • 5
  • 16
86me
  • 71
  • 1
  • 2
0

I find this function producing the most concise and clear output (it's not mine):

colors () {
    for i in {0..255}
    do
        print -Pn "%K{$i}  %k%F{$i}${(l:3::0:)i}%f " ${${(M)$((i%6)):#3}:+$'\n'}
    done
}

function output screenshot

Then you use colourXXX where XXX is the three digits code printed above as the value for fg=, bg= etc...

DJCrashdummy
  • 163
  • 1
  • 1
  • 11
elig
  • 169
  • 10