Skip to content

Instantly share code, notes, and snippets.

@pborenstein
Created August 10, 2014 03:49

Revisions

  1. pborenstein created this gist Aug 10, 2014.
    40 changes: 40 additions & 0 deletions colorsxterm.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,40 @@
    #! /usr/bin/env bash

    # print all the xterm colors
    # see http://serverfault.com/a/91873 about caculating the rgb values


    for c in {0..15}
    do
    printf "\033[38;5;%dm %2d" $c $c
    if (( (c+1) % 8 == 0 )) ; then
    echo
    fi
    done

    for r in {0..5}
    do
    for g in {0..5}
    do
    for b in {0..5}
    do
    (( rgb = (36 * $r) + (6 * $g) + $b + 16))
    (( nrgb = rgb - 16 ))
    printf "\033[38;5;%dm (%3d) %d %d %d" $rgb $rgb $r $g $b
    if (( (nrgb+1) % 6 == 0 )) ; then
    echo
    fi
    if (( g == 5 && b == 5 )) ; then
    echo
    fi
    done
    done
    done

    for c in {232..255}
    do
    printf "\033[38;5;%dm %2d" $c $c
    if (( (c+1) % 8 == 0 )) ; then
    echo
    fi
    done