]> git.wh0rd.org - home.git/commitdiff
bash-colors: remove redundant 0 prefixes
authorMike Frysinger <vapier@gmail.com>
Sat, 22 Aug 2026 16:33:59 +0000 (23:33 +0700)
committerMike Frysinger <vapier@gmail.com>
Sat, 22 Aug 2026 16:33:59 +0000 (23:33 +0700)
Leading 0 are stripped, and omitted numbers are automatically 0.

.bin/bash-colors

index ed61f8b3e131f81c2c8bae4b881d5a1c62b1579d..eaa1f25c970887f000a787a4dde282bc6a558cff 100755 (executable)
@@ -1,5 +1,5 @@
 #!/bin/bash
-# Author: Mike Frysinger <vapier@gmail.com>; released into the public domain; suck it.
+# Written by Mike Frysinger <vapier@gmail.com>.  Released into the public domain.
 
 # This is for bash.
 BASH_PREFIX="\e"
@@ -10,12 +10,12 @@ PREFIX=${BASH_PREFIX}
 
 show_env() {
        local c colors=(
-               GOOD="\$'${PREFIX}[32;01m'"
-               WARN="\$'${PREFIX}[33;01m'"
-               BAD="\$'${PREFIX}[31;01m'"
-               HILITE="\$'${PREFIX}[36;01m'"
-               BRACKET="\$'${PREFIX}[34;01m'"
-               NORMAL="\$'${PREFIX}[0m'"
+               GOOD="\$'${PREFIX}[32;1m'"
+               WARN="\$'${PREFIX}[33;1m'"
+               BAD="\$'${PREFIX}[31;1m'"
+               HILITE="\$'${PREFIX}[36;1m'"
+               BRACKET="\$'${PREFIX}[34;1m'"
+               NORMAL="\$'${PREFIX}[m'"
        )
        for c in "${colors[@]}" ; do
                [[ -t 0 ]] || c="${c%=*}="
@@ -34,7 +34,7 @@ check256() {
 
 showit() {
        local col="${PREFIX}[${1};${2}m"
-       printf '%bthis color is: %s   %b\n' "${col}" "${col}" "${PREFIX}[0m"
+       printf '%bthis color is: %s   %b\n' "${col}" "${col}" "${PREFIX}[m"
 }
 
 main() {
@@ -56,13 +56,13 @@ main() {
        cube|6x6x6)
                check256
                for n in {16..231} ; do
-                       showit "38;05" $(printf '%03i' ${n})
+                       showit "38;5" $(printf '%03i' ${n})
                done
                ;;
        gr[ae]y)
                check256
                for n in {232..255} ; do
-                       showit "38;05" ${n}
+                       showit "38;5" ${n}
                done
                ;;
        all|256)