@@ -40,7 +40,7 @@ readonly PROG_VERSION='2.6.0-dev'
4040# util functions
4141# ###############################################################################
4242
43- readonly red =' \033[1;31m ' normal= ' \033 [0m'
43+ readonly color_reset =' \e [0m'
4444
4545# How to delete line with echo?
4646# https://unix.stackexchange.com/questions/26576
@@ -50,12 +50,14 @@ readonly red='\033[1;31m' normal='\033[0m'
5050# echo -e "\033[1K"
5151# Or everything on the line, regardless of cursor position:
5252# echo -e "\033[2K"
53- readonly clear_line=' \033 [2K\r'
53+ readonly clear_line=' \e [2K\r'
5454
5555redPrint () {
56- # -t check: is a terminal device?
56+ # if stdout is a terminal, turn on color output.
57+ # '-t' check: is a terminal?
58+ # check isatty in bash https://stackoverflow.com/questions/10022323
5759 if [ -t 1 ]; then
58- printf " ${red} %s${normal } \n" " $* "
60+ printf " \e[1;31m %s${color_reset } \n" " $* "
5961 else
6062 printf ' %s\n' " $* "
6163 fi
@@ -72,17 +74,17 @@ printResponsiveMessage() {
7274 return
7375 fi
7476
75- local message =" $* "
77+ local content =" $* "
7678 # http://www.linuxforums.org/forum/red-hat-fedora-linux/142825-how-truncate-string-bash-script.html
77- printf " ${clear_line} %s " " ${message : 0: columns} " >&2
79+ printf %b%s " ${clear_line} " " ${content : 0: columns} " >&2
7880}
7981
8082clearResponsiveMessage () {
8183 if ! $show_responsive || [ ! -t 2 ]; then
8284 return
8385 fi
8486
85- printf " %b " " $clear_line " >&2
87+ printf %b " $clear_line " >&2
8688}
8789
8890die () {
@@ -322,14 +324,14 @@ listZipEntries() {
322324 clearResponsiveMessage
323325 redPrint " fail to list zip entries of $zip_file , ignored: $msg " >&2
324326 fi
325- return 0
327+ return
326328 }
327329 fi
328330
329331 " ${command_to_list_zip_entries[@]} " " $zip_file " || {
330332 clearResponsiveMessage
331333 redPrint " fail to list zip entries of $zip_file , ignored!" >&2
332- return 0
334+ return
333335 }
334336}
335337
@@ -347,16 +349,14 @@ searchJarFiles() {
347349
348350 total_jar_count=" $( printf ' %s\n' " $jar_files " | wc -l) "
349351 # remove white space, because the `wc -l` output on mac contains white space!
350- total_jar_count=" ${total_jar_count// [[:space:]]/ } "
352+ total_jar_count=${total_jar_count// [[:space:]]}
351353
352354 echo " $total_jar_count "
353355 printf ' %s\n' " $jar_files "
354356}
355357
356- readonly jar_color=' \033[1;35m' sep_color=' \033[1;32m'
357-
358358__outputResultOfJarFile () {
359- local jar_file=" $1 " file
359+ local jar_file=" $1 " file jar_color= ' \e[1;35m ' sep_color= ' \e[1;32m '
360360 # shellcheck disable=SC2206
361361 local grep_opt_args=(" $regex_mode " ${ignore_case_option:- } ${grep_color_option:- } -- " $pattern " )
362362
@@ -380,7 +380,7 @@ __outputResultOfJarFile() {
380380
381381 clearResponsiveMessage
382382 if [ -t 1 ]; then
383- printf " ${jar_color} %s${normal } \n" " ${jar_file} "
383+ printf " ${jar_color} %s${color_reset } \n" " ${jar_file} "
384384 else
385385 printf ' %s\n' " ${jar_file} "
386386 fi
@@ -392,7 +392,7 @@ __outputResultOfJarFile() {
392392 } | while read -r file; do
393393 clearResponsiveMessage
394394 if [ -t 1 ]; then
395- printf " ${jar_color} %s${sep_color} %s${normal } %s\n" " $jar_file " " $separator " " $file "
395+ printf " ${jar_color} %s${sep_color} %s${color_reset } %s\n" " $jar_file " " $separator " " $file "
396396 else
397397 printf ' %s\n' " ${jar_file}${separator}${file} "
398398 fi
0 commit comments