Last active
June 18, 2019 00:59
-
-
Save lebensterben/2548f75ea24becc7ac3dd1478397f1a7 to your computer and use it in GitHub Desktop.
[DEPRECATED ]A simple zsh function to output term colors
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## color-test | |
colortest () { | |
colortest_usage () { | |
echo -e "Usage: colortest [[-v|--verbose] | [-a|--all] | [-h|--help]]\n\nPrint out colors available in this terminal emulator. The default output is a short list of colors. If -v or --verbose is specified, a table containing all combination of background and foreground colors is displayed. Alternatively, if -a or -all is specified, then both short list and the detailed table would be displayed.\n\nNote that there should be no argument to this programme.\n -v, --verbose\t displays a table with detailed table of combinations of colors.\n -a, --all \t displays both brief and detailed results.\n -h, --help \t displays this help." | |
} | |
if [[ "$#" > 1 ]]; then | |
echo -e "$0: Error(1): At most one flag is allowed." >&2 | logger | |
colortest_usage | |
unset colortest_usage | |
return 1 | |
fi | |
colortest_short () { | |
### gives the color table (text) | |
echo -e "\033[0mNC (No color)" | |
echo -e "\033[0;30mBLACK \t\033[1;30mGRAY" | |
echo -e "\033[0;31mRED \t\033[1;31mLIGHT_RED" | |
echo -e "\033[0;32mGREEN \t\033[1;32mLIGHT_GREEN" | |
echo -e "\033[0;33mYELLOW \t\033[1;33mLIGHT_YELLOW" | |
echo -e "\033[0;34mBLUE \t\033[1;34mLIGHT_BLUE" | |
echo -e "\033[0;35mPURPLE \t\033[1;35mLIGHT_PURPLE" | |
echo -e "\033[0;36mCYAN \t\033[1;36mLIGHT_CYAN" | |
echo -e "\033[0;37mLIGHT_GRAY\t\033[1;37mWHITE\033[0m" | |
} | |
if [[ "$#" -eq 0 ]]; then | |
colortest_short | |
unset -f colortest_usage colortest_short | |
return 1 | |
fi | |
option=$(getopt -q -o vha --long verbose,help,all -- "$@") | |
if [[ ! "$?" -eq 0 ]]; then | |
echo -e "$0: Error(1): Unrecognized option $1." >&2 | logger | |
colortest_usage | |
unset -f colortest_usage colortest_short | |
unset option | |
return 1 | |
fi | |
colortest_long () { | |
### gives the color table | |
printf " " | |
for b in 0 1 2 3 4 5 6 7; do | |
printf " 4${b}m " | |
done | |
echo | |
for f in "" 30 31 32 33 34 35 36 37; do | |
for s in "" "1;"; do | |
printf "%4sm" "${s}${f}" | |
printf " \033[%sm%s\033[0m" "$s$f" "gYw " | |
for b in 0 1 2 3 4 5 6 7; do | |
printf " \033[4%s;%sm%s\033[0m" "$b" "$s$f" " gYw " | |
done | |
echo | |
done | |
done | |
} | |
while [[ "$#" > 0 ]]; do | |
case "$1" in | |
-h|--help) colortest_usage;; | |
-v|--verbose) colortest_long;; | |
-a|--all) colortest_short; colortest_long;; | |
--) colortest_short;; | |
*) echo "$0: Error(1): This function doesn't accept any argument." >&2 | logger; colortest_usage;unset -f colortest_usage colortest_short colortest_long; option; return 1;; | |
esac | |
shift | |
done | |
unset -f colortest_usage colortest_short colortest_long | |
unset option | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This implementation only works for
zsh
. It shall be put under$fpath
and be autoloaded byzsh
.