]> git.wh0rd.org - home.git/blob - .bin/bash-colors
backup-dvd: sync disk after each major step
[home.git] / .bin / bash-colors
1 #!/bin/bash
2 # Author: Mike Frysinger <vapier@gmail.com>; released into the public domain; suck it.
3
4 show_env() {
5 local c colors=(
6 GOOD="\$'\e[32;01m'"
7 WARN="\$'\e[33;01m'"
8 BAD="\$'\e[31;01m'"
9 HILITE="\$'\e[36;01m'"
10 BRACKET="\$'\e[34;01m'"
11 NORMAL="\$'\e[0m'"
12 )
13 for c in "${colors[@]}" ; do
14 [[ -t 0 ]] || c="${c%=*}="
15 echo "${c}"
16 done
17 }
18
19 check256() {
20 if [[ ${TERM} != *-256color ]] ; then
21 (
22 echo "warning: TERM (${TERM}) does not end in '-256color';"
23 echo "warning: trying to use 256 colors might not work."
24 ) >&2
25 fi
26 }
27
28 showit() {
29 echo -e '\e['"${1};${2}mthis color is: \\\\e[${1};${2}m \e[0m"
30 }
31
32 main() {
33 case $1 in
34 --env)
35 show_env
36 ;;
37 ""|16|system)
38 for i in {0..1} ; do
39 for j in {30..37} ; do
40 showit ${i} ${j}
41 done
42 done
43 ;;
44 cube|6x6x6)
45 check256
46 for n in {16..231} ; do
47 showit "38;05" $(printf '%03i' ${n})
48 done
49 ;;
50 gr[ae]y)
51 check256
52 for n in {232..255} ; do
53 showit "38;05" ${n}
54 done
55 ;;
56 all|256)
57 for x in system cube gray ; do
58 echo "### SET: ${x}"
59 "$0" ${x}
60 done
61 ;;
62 ncurses|curses|mutt|nano)
63 colors=(
64 black
65 red
66 green
67 yellow
68 blue
69 magenta
70 cyan
71 white
72 )
73 norm=$(tput sgr0)
74 bold=$(tput bold)
75 blackfg=$(tput setaf 0)
76 for seta in "af" "ab" ; do
77 [[ ${seta} == "af" ]] && ground=fore || ground=back
78 for pfx in "" "bright" ; do
79 for (( i = 0; i < ${#colors[@]}; ++i )) ; do
80 [[ ${pfx} == "bright" ]] && printf "${bold}"
81 [[ ${seta} == "ab" ]] && printf "${blackfg}"
82 echo "$(tput set${seta} ${i})this is ${ground}ground color '${pfx}${colors[i]}'${norm}"
83 done
84 done
85 done
86 ;;
87 *)
88 cat <<-EOF
89 usage: $0 [colors]
90
91 Colors:
92 - --env - show env you can eval in a shell
93 - 16, system - show basic colors (default)
94 - cube, 6x6x6 - show most extended colors
95 - gray - show gray scale
96 - all, 256 - show all colors
97 - curses - show ncurses color names (used by mutt, nano, etc...)
98 EOF
99 exit 1
100 ;;
101 esac
102 }
103 main "$@"