diff options
author | merakor <cem@ckyln.com> | 2020-09-05 09:51:19 +0000 |
---|---|---|
committer | merakor <cem@ckyln.com> | 2020-09-05 09:51:19 +0000 |
commit | fb59a3a43cd81f3da5492cb2e6f51ee77f8b6204 (patch) | |
tree | 101408a67b6e4c1d32b0da5dce27a7d26cff0c97 | |
parent | 5416e51a84066536701d503163512c2f5616d23b (diff) | |
download | cpt-fb59a3a43cd81f3da5492cb2e6f51ee77f8b6204.tar.gz |
cpt: add back support for setting colors, fix shellcheck error
FossilOrigin-Name: 4353efa436df913e647c5b43c709833fb76d12fb52d9db1b9bbaff04e55d0abf
-rwxr-xr-x | src/cpt | 5 | ||||
-rw-r--r-- | src/cpt-lib | 15 |
2 files changed, 12 insertions, 8 deletions
@@ -1,7 +1,6 @@ #!/bin/sh -ef -# shellcheck disable=1091 -if command -v cpt-lib >/dev/null; then . cpt-lib; else . ./cpt-lib; fi +if [ -f ./cpt-lib ]; then . ./cpt-lib; else . cpt-lib; fi # If none of the tools below are specified, we will reenable glob unset glob @@ -20,7 +19,7 @@ case "$arg" in # These are the files to be ignored. contains "lib readlink stat" "$path" && continue - printf "%b->%b %-${max}s " "${color:+\033[1;31m}" "${color:+\033[m}" "${path#*/cpt-}" + printf "%b->%b %-${max}s " "$colorb" "$colre" "${path#*/cpt-}" sed -n 's/^# *//;2p' "$(command -v "cpt-$path")" done | sort -uk1 >&2 exit diff --git a/src/cpt-lib b/src/cpt-lib index 6957841..38e57c1 100644 --- a/src/cpt-lib +++ b/src/cpt-lib @@ -23,12 +23,10 @@ log() { # All messages are printed to stderr to allow the user to hide build # output which is the only thing printed to stdout. # - # '\033[1;32m' Set text to color '2' and make it bold. - # '\033[m': Reset text formatting. # '${3:-->}': If the 3rd argument is missing, set prefix to '->'. - # '${2:+\033[1;3Xm}': If the 2nd argument exists, set text style of '$1'. - printf '\033[1;33m%s \033[m%b%s\033[m %s\n' \ - "${3:-->}" "${2:+"\033[1;36m"}" "$1" "$2" >&2 + # '${2:+colorb}': If the 2nd argument exists, set text style of '$1'. + printf '%b%s %b%b%s%b %s\n' \ + "$colory" "${3:-->}" "$colre" "${2:+$colorb}" "$1" "$colre" "$2" >&2 } die() { @@ -1825,6 +1823,13 @@ main() { # Set a value for CPT_COMPRESS if it isn't set. : "${CPT_COMPRESS:=gz}" + # Unless being piped or the user specifically doesn't want colors, set + # colors. This can of course be overriden if the user specifically want + # colors during piping. + if { [ "$CPT_COLOR" != 0 ] && [ -t 1 ] ;} || [ "$CPT_COLOR" = 1 ]; then + colory="\033[1;33m" colorb="\033[1;36m" colre="\033[m" + fi + } main "$@" |