Skip to content

Instantly share code, notes, and snippets.

@mpontillo
Created January 10, 2017 02:17
Show Gist options
  • Save mpontillo/4d1d216c5d5a32a848c532a8d4408c7e to your computer and use it in GitHub Desktop.
Save mpontillo/4d1d216c5d5a32a848c532a8d4408c7e to your computer and use it in GitHub Desktop.
Use `tput` to show some different combinations of colors and settings.
#!/bin/bash
function normal {
tput sgr0
}
normal="$(normal)"
function example {
printf "%s" "${normal}"
COMMAND=()
while [ -n "$1" ]; do
if [ "$1" == "setaf" ]; then
tput $1 $2
printf "tput $1 $2; "
shift
shift
else
tput $1
printf "tput $1; "
shift
fi
done
printf "%s" "${normal}"
}
echo "${normal}Reset: tput sgr0;"
echo ""
echo "Non-bold ANSI colors:"
i=0; while [ $i -lt 8 ]; do
echo "${normal}Example: $(example setaf $i)"
let i=$i+1
done
echo "${normal}"
echo "Non-bold ANSI colors:"
i=0; while [ $i -lt 8 ]; do
echo "${normal}Example: $(example bold setaf $i)"
let i=$i+1
done
echo "${normal}"
echo "Reverse video:"
i=0; while [ $i -lt 8 ]; do
echo "${normal}Example: $(example rev setaf $i)"
let i=$i+1
done
echo "${normal}"
echo "Bold reverse video:"
i=0; while [ $i -lt 8 ]; do
echo "${normal}Example: $(example rev bold setaf $i)"
let i=$i+1
done
echo "${normal}"
echo "Underline:"
i=0; while [ $i -lt 8 ]; do
echo "${normal}Example: $(example smul setaf $i)"
let i=$i+1
done
echo "${normal}"
echo "Bold underline:"
i=0; while [ $i -lt 8 ]; do
echo "${normal}Example: $(example smul bold setaf $i)"
let i=$i+1
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment