dotfiles

My personal shell configs and stuff
git clone git://git.alex.balgavy.eu/dotfiles.git
Log | Files | Refs | Submodules | README | LICENSE

print-colors (598B)


      1 #!/bin/sh
      2 die() { printf '%s\n' "$1" >&2 && exit 1; }
      3 
      4 command -v tput > /dev/null 2>&1 || die "tput not installed."
      5 
      6 [ -z "$(printf '%s' "$1" | tr -d '0-9')" ] || die 'Usage: tput-colors [number]'
      7 # Print out 16 colors by default
      8 [ "$#" -eq 0 ] && set -- 16
      9 
     10 tput init >/dev/null 2>&1
     11 
     12 : $((i=0))
     13 while [ $((i < $1)) -ne 0 ]; do
     14   case $i in 0) pref="(black)";; 1) pref="(red)";; 2) pref="(green)";; 3) pref="(yellow)";; 4) pref="(blue)";; 5) pref="(magenta)";; 6) pref="(cyan)";; 7) pref="(white)";; *) pref="";; esac
     15   echo "$(tput sgr0)$i$pref $(tput setaf "$i")sample text"
     16   i=$((i+1))
     17 done
     18