#!/usr/bin/env bash trap 'tput sgr0' exit # Clean up even if user hits ^C function setfg () { printf '\e[38;5;%dm' $1 } function setbg () { printf '\e[48;5;%dm' $1 } function showcolors() { # Given an integer, display that many colors for ((i=0; i<$1; i++)) do printf '%4d ' $i setbg $i tput el tput sgr0 echo done tput sgr0 el } ### Main starts here # First, test if terminal supports OSC 4 at all. printf '\e]4;%d;?\a' 0 read -d $'\a' -s -t 0.1