aboutsummaryrefslogtreecommitdiff
path: root/kiss
diff options
context:
space:
mode:
authormerakor <cem@ckyln.com>2020-05-07 16:59:26 +0000
committermerakor <cem@ckyln.com>2020-05-07 16:59:26 +0000
commit92c57e7dff0b855ec6e96558d8421f50396cc35f (patch)
tree298ea22595189d398ad005ebd3a2be09be23183d /kiss
parent8dab0c3652d6a9e3cf18107b04dce5b0c6e50e1b (diff)
downloadcpt-92c57e7dff0b855ec6e96558d8421f50396cc35f.tar.gz
kiss: disable colour escape sequences if running in a subshell
Since some pagers don't handle colour escape sequences, this will come in handy for things like piping into programs. This behaviour can be disabled by adding a KISS_COLOUR environment variable. FossilOrigin-Name: 9c06d36861b43c08f1862a27350b5bbe4db2ba31f44ad9c5b49ca2c42bfd3077
Diffstat (limited to 'kiss')
-rwxr-xr-xkiss21
1 files changed, 17 insertions, 4 deletions
diff --git a/kiss b/kiss
index 8aea4b3..ebb20bc 100755
--- a/kiss
+++ b/kiss
@@ -1425,11 +1425,15 @@ args() {
# of messages from packages.
log "Retrieving post-installation message queue"
unset msg
+
+ [ "$KISS_COLOUR" ] || [ -t 1 ] &&
+ colour=1
+
for pkg in $order; do
if [ -f "$sys_db/$pkg/message" ]; then
- printf '%s\n\033[1m%s\033[m\n%s\n\n' \
+ printf '%s\n%b%s%b\n%s\n\n' \
"==============================" \
- "$pkg" \
+ "${colour:+"\033[1m"}" "$pkg" "${colour:+"\033[m"}" \
"==============================" >&2
cat "$sys_db/$pkg/message" >&2
msg=1
@@ -1440,6 +1444,8 @@ args() {
e|extension)
log "Installed extensions"
+ [ "$KISS_COLOUR" ] ||
+ [ -t 1 ] && colour=1
set --
@@ -1452,8 +1458,9 @@ args() {
# These are binary files so they should be ignored
contains "readlink stat" "$path" && continue
- printf '\033[31;1m->\033[m %-*s ' "$max" "${path#*/kiss-}"
- sed -n 's/^# *//;2p' "$(command -v "kiss-$path")"
+ printf '%b->%b %-*s ' "${colour:+"\033[1;31m"}" "${colour:+"\033[m"}" \
+ "$max" "${path#*/kiss-}"
+ sed -n 's/^# *//;2p' "$(command -v "kiss-$path")"
done | sort -uk1 >&2
;;
@@ -1569,6 +1576,12 @@ main() {
"${log_dir:=$cac_dir/logs}" \
"${bin_dir:=$cac_dir/bin}"
+ # Disable colour escape sequences if running in a subshell.
+ # This behaviour can be disabled by adding a KISS_COLOUR
+ # variable to the environment.
+ [ "$KISS_COLOUR" ] || [ -t 1 ] ||
+ log() { printf '%s %s %s\n' "${3:-->}" "$1" "$2" >&2 ;}
+
args "$@"
}