]> git.wh0rd.org - home.git/blob - .bin/bash-colors
bash-colors: improve it
[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 *)
63 cat <<-EOF
64 usage: $0 [colors]
65
66 Colors:
67 - --env - show env you can eval in a shell
68 - 16, system - show basic colors (default)
69 - cube, 6x6x6 - show most extended colors
70 - gray - show gray scale
71 - all, 256 - show all colors
72 EOF
73 exit 1
74 ;;
75 esac
76 }
77 main "$@"