Skip to content

Instantly share code, notes, and snippets.

@addohm
Forked from dtmilano/colors
Created February 7, 2024 16:29
Show Gist options
  • Save addohm/04e85b47bfccf366b1929538bddbae5d to your computer and use it in GitHub Desktop.
Save addohm/04e85b47bfccf366b1929538bddbae5d to your computer and use it in GitHub Desktop.

Revisions

  1. @dtmilano dtmilano created this gist Nov 26, 2019.
    55 changes: 55 additions & 0 deletions colors
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,55 @@
    #! /bin/bash

    n=32
    arg=setaf
    text='Hello World! This is %s %d'

    _help()
    {
    printf 'usage: %s [--help|-H] [--16] [--256] [-t|--tiny] [--background|-b]\n' "$(basename $0)"
    exit 0
    }

    while (( $# > 0 ))
    do
    case "$1" in
    256|--256|-256)
    n=256
    shift
    ;;

    16|--16|-16)
    n=16
    shift
    ;;

    --background|-b)
    arg=setab
    shift
    ;;

    --tiny|-t)
    text=''
    shift
    ;;

    --help|-H)
    _help
    ;;

    --*|-*)
    _help
    ;;
    esac
    done

    for f in $(seq $n)
    do
    tput $arg $f
    printf "$text" $arg $f
    tput sgr0
    if (( f % 16 == 0 )) || [[ "$arg" == 'setab' ]] || [[ "$text" != '' ]]
    then
    printf '\n'
    fi
    done