aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xsrc/cpt5
-rw-r--r--src/cpt-lib15
2 files changed, 12 insertions, 8 deletions
diff --git a/src/cpt b/src/cpt
index b3081f9..0c0f688 100755
--- a/src/cpt
+++ b/src/cpt
@@ -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 "$@"