]> git.wh0rd.org - home.git/blame - .bin/bash-colors
redshift-check: silence "using method" message
[home.git] / .bin / bash-colors
CommitLineData
8069c098 1#!/bin/bash
412ff3c0 2# Author: Mike Frysinger <vapier@gmail.com>; released into the public domain; suck it.
ea2a7d52 3
412ff3c0
MF
4show_env() {
5 local c colors=(
ea2a7d52
MF
6 GOOD="\$'\e[32;01m'"
7 WARN="\$'\e[33;01m'"
8 BAD="\$'\e[31;01m'"
9 HILITE="\$'\e[36;01m'"
583623f9 10 BRACKET="\$'\e[34;01m'"
ea2a7d52
MF
11 NORMAL="\$'\e[0m'"
12 )
13 for c in "${colors[@]}" ; do
b73f07c7 14 [[ -t 0 ]] || c="${c%=*}="
ea2a7d52
MF
15 echo "${c}"
16 done
412ff3c0 17}
ea2a7d52 18
412ff3c0
MF
19check256() {
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}
ea2a7d52 27
ee33e474
MF
28showit() {
29 echo -e '\e['"${1};${2}mthis color is: \\\\e[${1};${2}m \e[0m"
30}
412ff3c0
MF
31
32main() {
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
ee33e474 42 done
412ff3c0
MF
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 ;;
1f3bf8d2
MF
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 ;;
412ff3c0
MF
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
1f3bf8d2 97 - curses - show ncurses color names (used by mutt, nano, etc...)
412ff3c0
MF
98 EOF
99 exit 1
100 ;;
101 esac
102}
103main "$@"