]> git.wh0rd.org - home.git/blobdiff - .bin/bash-colors
gdbinit: split up & migrate some to python
[home.git] / .bin / bash-colors
index 820958b67f5b341673e2303a54c55a13bbcea481..ed61f8b3e131f81c2c8bae4b881d5a1c62b1579d 100755 (executable)
@@ -1,14 +1,21 @@
 #!/bin/bash
 # Author: Mike Frysinger <vapier@gmail.com>; released into the public domain; suck it.
 
+# This is for bash.
+BASH_PREFIX="\e"
+# And this is the portable one.
+POSIX_PREFIX="\033"
+# Default to bash.
+PREFIX=${BASH_PREFIX}
+
 show_env() {
        local c colors=(
-               GOOD="\$'\e[32;01m'"
-               WARN="\$'\e[33;01m'"
-               BAD="\$'\e[31;01m'"
-               HILITE="\$'\e[36;01m'"
-               BRACKET="\$'\e[34;01m'"
-               NORMAL="\$'\e[0m'"
+               GOOD="\$'${PREFIX}[32;01m'"
+               WARN="\$'${PREFIX}[33;01m'"
+               BAD="\$'${PREFIX}[31;01m'"
+               HILITE="\$'${PREFIX}[36;01m'"
+               BRACKET="\$'${PREFIX}[34;01m'"
+               NORMAL="\$'${PREFIX}[0m'"
        )
        for c in "${colors[@]}" ; do
                [[ -t 0 ]] || c="${c%=*}="
@@ -26,10 +33,15 @@ check256() {
 }
 
 showit() {
-       echo -e '\e['"${1};${2}mthis color is: \\\\e[${1};${2}m    \e[0m"
+       local col="${PREFIX}[${1};${2}m"
+       printf '%bthis color is: %s   %b\n' "${col}" "${col}" "${PREFIX}[0m"
 }
 
 main() {
+       if [[ $1 == "--posix" ]] ; then
+               PREFIX=${POSIX_PREFIX}
+               shift
+       fi
        case $1 in
        --env)
                show_env
@@ -59,9 +71,34 @@ main() {
                        "$0" ${x}
                done
                ;;
+       ncurses|curses|mutt|nano)
+               colors=(
+                       black
+                       red
+                       green
+                       yellow
+                       blue
+                       magenta
+                       cyan
+                       white
+               )
+               norm=$(tput sgr0)
+               bold=$(tput bold)
+               blackfg=$(tput setaf 0)
+               for seta in "af" "ab" ; do
+                       [[ ${seta} == "af" ]] && ground=fore || ground=back
+                       for pfx in "" "bright" ; do
+                               for (( i = 0; i < ${#colors[@]}; ++i )) ; do
+                                       [[ ${pfx} == "bright" ]] && printf "${bold}"
+                                       [[ ${seta} == "ab" ]] && printf "${blackfg}"
+                                       echo "$(tput set${seta} ${i})this is ${ground}ground color '${pfx}${colors[i]}'${norm}"
+                               done
+                       done
+               done
+               ;;
        *)
                cat <<-EOF
-                       usage: $0 [colors]
+                       usage: $0 [--posix] [colors]
 
                        Colors:
                         - --env        - show env you can eval in a shell
@@ -69,6 +106,7 @@ main() {
                         - cube, 6x6x6  - show most extended colors
                         - gray         - show gray scale
                         - all, 256     - show all colors
+                        - curses       - show ncurses color names (used by mutt, nano, etc...)
                EOF
                exit 1
                ;;