prcolors: major bug fixes and formatting, and zsh is now the shell (fixes option 3)

This commit is contained in:
PowerUser64 2022-02-06 22:14:44 -08:00
parent da5d2d9597
commit 4dd6db0386

View file

@ -1,90 +1,90 @@
#!/bin/bash #!/bin/zsh
# prcolors: Display all colors in a few different ways >>> # prcolors: Display all colors in a few different ways >>>
# TODO: change this to make it not just a few scripts smashed together # TODO: change this to make it not just a few scripts smashed together
[ -z "$1" ] && 1=0 if [ "$1" -gt 0 ] && [ "$1" -lt 4 ]; then
if [ $1 -eq '1' ];then if [ $1 = '1' ];then
# Taken from manjaro's bashrc >>> # Taken from manjaro's bashrc >>>
local fgc bgc vals seq0 local fgc bgc vals seq0
printf "Color escapes are %s\n" '\e[${value};...;${value}m' printf "Color escapes are %s\n" '\e[${value};...;${value}m'
printf "Values 30..37 are \e[33mforeground colors\e[m\n" printf "Values 30..37 are \e[33mforeground colors\e[m\n"
printf "Values 40..47 are \e[43mbackground colors\e[m\n" printf "Values 40..47 are \e[43mbackground colors\e[m\n"
printf "Value 1 gives a \e[1mbold-faced look\e[m\n\n" printf "Value 1 gives a \e[1mbold-faced look\e[m\n\n"
# foreground colors # foreground colors
for fgc in {30..37}; do for fgc in {30..37}; do
# background colors # background colors
for bgc in {40..47}; do for bgc in {40..47}; do
fgc=${fgc#37} # white fgc=${fgc#37} # white
bgc=${bgc#40} # black bgc=${bgc#40} # black
vals="${fgc:+$fgc;}${bgc}" vals="${fgc:+$fgc;}${bgc}"
vals=${vals%%;} vals=${vals%%;}
seq0="${vals:+\e[${vals}m}" seq0="${vals:+\e[${vals}m}"
printf " %-9s" "${seq0:-(default)}" printf " %-9s" "${seq0:-(default)}"
printf " ${seq0}TEXT\e[m" printf " ${seq0}TEXT\e[m"
printf " \e[${vals:+${vals+$vals;}}1mBOLD\e[m" printf " \e[${vals:+${vals+$vals;}}1mBOLD\e[m"
done
echo; echo
done done
echo; echo # <<<
done elif [ $1 = '2' ];then
# <<< # from base16shell >>>
elif [ $1 -eq '2' ];then ansi_mappings=(
# from base16shell >>> Red Green
ansi_mappings=( Yellow Blue
Red Green Magenta Cyan
Yellow Blue White Black
Magenta Cyan Bright_Red Bright_Green
White Black Bright_Yellow Bright_Blue
Bright_Red Bright_Green Bright_Magenta Bright_Cyan
Bright_Yellow Bright_Blue Bright_White Bright_Black
Bright_Magenta Bright_Cyan )
Bright_White Bright_Black colors=(
) base00 base08
colors=( base0B base0A
base00 base08 base0D base0E
base0B base0A base0C base05
base0D base0E base03 base08
base0C base05 base0B base0A
base03 base08 base0D base0E
base0B base0A base0C base07
base0D base0E base09 base0F
base0C base07 base01 base02
base09 base0F base04 base06
base01 base02 )
base04 base06 for padded_value in `seq -w 0 21`; do
) color_variable="color${padded_value}"
for padded_value in `seq -w 0 21`; do eval current_color=\$${color_variable}
color_variable="color${padded_value}" current_color=$(echo ${current_color//\//} | tr '[:lower:]' '[:upper:]') # get rid of slashes, and uppercase
eval current_color=\$${color_variable} non_padded_value=$((10#$padded_value))
current_color=$(echo ${current_color//\//} | tr '[:lower:]' '[:upper:]') # get rid of slashes, and uppercase base16_color_name=${colors[$non_padded_value]}
non_padded_value=$((10#$padded_value)) current_color_label=${current_color:-unknown}
base16_color_name=${colors[$non_padded_value]} ansi_label=${ansi_mappings[$non_padded_value]}
current_color_label=${current_color:-unknown} block=$(printf "\x1b[48;5;${non_padded_value}m___________________________")
ansi_label=${ansi_mappings[$non_padded_value]} foreground=$(printf "\x1b[38;5;${non_padded_value}m$color_variable")
block=$(printf "\x1b[48;5;${non_padded_value}m___________________________") printf "%s %s %s %-30s %s\x1b[0m\n" $foreground $base16_color_name $current_color_label ${ansi_label:-""} $block
foreground=$(printf "\x1b[38;5;${non_padded_value}m$color_variable") done;
printf "%s %s %s %-30s %s\x1b[0m\n" $foreground $base16_color_name $current_color_label ${ansi_label:-""} $block #if [ $# -eq 1 ]; then
done; # printf "To restore current theme, source ~/.base16_theme or reopen your terminal\n"
#if [ $# -eq 1 ]; then #fi
# printf "To restore current theme, source ~/.base16_theme or reopen your terminal\n" # <<<
#fi elif [ $1 = '3' ];then
# <<< # Similar to above, but does 256-bit colors. >>>
elif [ $1 -eq '3' ];then # Taken from this: https://github.com/romkatv/powerlevel10k#set-colors-through-Powerlevel10k-configuration-parameters
# Similar to above, but does 256-bit colors. >>> for i in {0..255}; do print -Pn "%K{$i} %k%F{$i}${(l:3::0:)i}%f " ${${(M)$((i%6)):#3}:+$'\n'}; done
# Taken from this: https://github.com/romkatv/powerlevel10k#set-colors-through-Powerlevel10k-configuration-parameters # <<<
for i in {0..255}; do fi
print -Pn "%K{$i} %k%F{$i}${(l:3::0:)i}%f " ${${(M)$((i%6)):#3}:+$'\n'}
done
# <<<
else else
cat <<-EOF cat <<-EOF
Usage: prcolors <printing method number> Usage: prcolors <printing method number>
1: Manjaro bashrc -- for checking text readability 1: Manjaro bashrc -- for checking text readability
2: base26shell -- for seeing the 16 set terminal colors 2: base26shell -- for seeing the 16 set terminal colors
3: 256 -- for testing 256 color output 3: 256 -- for testing 256 color output
EOF EOF
fi fi
# vim:foldmarker=>>>,<<< fdm=marker foldlevel=1