From 9522913ff437688085fe74f94d271115b95b04d8 Mon Sep 17 00:00:00 2001 From: The Magician Date: Mon, 20 Nov 2023 21:11:33 +0000 Subject: [PATCH] Fix issues found with shellcheck --- thebookofcolors | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/thebookofcolors b/thebookofcolors index 134b765..4a2baf4 100755 --- a/thebookofcolors +++ b/thebookofcolors @@ -10,19 +10,19 @@ random_rgb_color_pair() { red="$(random_channel_strength)" green="$(random_channel_strength)" blue="$(random_channel_strength)" - printf "$red;$green;$blue|$((255 - $red));$((255 - green));$((255 - blue))" + printf "%s;%s;%s|$((255 - red));$((255 - green));$((255 - blue))" "$red" "$green" "$blue" } thebookofcolors() { colors=$(random_rgb_color_pair) - foreground="$(echo $colors | cut -d '|' -f 1)" - background="$(echo $colors | cut -d '|' -f 2)" - printf "\e[38;2;${foreground}m" - printf "\e[48;2;${background}m" + foreground="$(echo "$colors" | cut -d '|' -f 1)" + background="$(echo "$colors" | cut -d '|' -f 2)" + printf "\e[38;2;%sm" "$foreground" + printf "\e[48;2;%sm" "$background" if test -z "$1"; then printf "The Book of Colors" else - printf "$1" + printf "%s" "$1" fi printf "\e[0m" } @@ -33,7 +33,7 @@ newline() { return fi - for i in $(seq 1 $1); do + for i in $(seq 1 "$1"); do printf "\n" done } @@ -45,7 +45,7 @@ title() { fi printf "\e[1;4;37m" - printf "$1" + printf "%s" "$1" printf "\e[0m\n" } @@ -56,7 +56,7 @@ subtitle() { fi printf "\e[4;37m" - printf "$1" + printf "%s" "$1" printf "\e[0m" if test -z "$2"; then printf "\n"; fi } @@ -72,7 +72,7 @@ italic() { fi printf "\e[3;37m" - printf "$1" + printf "%s" "$1" printf "\e[0m" } @@ -229,7 +229,7 @@ section_8bit_colors() { subtitle "A Table of Available Colors" for i in $(seq 0 255); do - if test "$(echo $i % 8 | bc)" = "0" -a "$i" != "0"; then + if test "$(echo "$i" % 8 | bc)" = "0" -a "$i" != "0"; then printf "\n" fi @@ -464,7 +464,7 @@ section_strikethrough() { section_using_escape_sequences_in_shell_prompt() { title "Using Escape Sequences in Shell Prompts" - printf "When using these sequences in a Bash prompt (e.g. $PS1), it's possible for issues to arise because of Bash \"miscounting\" the number of characters in the prompt string.\n" + printf "When using these sequences in a Bash prompt (e.g. \$PS1), it's possible for issues to arise because of Bash \"miscounting\" the number of characters in the prompt string.\n" printf "This is often the source of difficult-to-debug (or describe) issues with the terminal, such as characters being moved around or overwritten seemingly at random.\n" newline @@ -481,7 +481,7 @@ section_table_of_all_sgr_commands() { newline for i in $(seq 0 107); do - if test "$(echo $i % 10 | bc)" = "0" -a "$i" != "0"; then + if test "$(echo "$i" % 10 | bc)" = "0" -a "$i" != "0"; then printf "\n" fi @@ -582,7 +582,7 @@ main() { newline } -name="$(basename $0)" +name="$(basename "$0")" if test "$name" = "thebookofcolors"; then main | less -R fi