summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobin Candau <antiz@archlinux.org>2024-01-19 02:05:40 +0000
committerDaniel M. Capella <polyzen@archlinux.org>2024-01-19 02:05:40 +0000
commit53c94a04ba47e3e4d42479b34156c8931dc53a61 (patch)
tree7f3dd5b3638a1515389d29b852c67b4e9cab8e36
parent4dfabeadfbcf700ed71cea38fb24f0925e6d1bfc (diff)
Checkupdates: Preserve pacman colors when printing the list of pending updates
-rw-r--r--doc/checkupdates.8.adoc11
-rw-r--r--src/checkupdates.sh.in25
2 files changed, 24 insertions, 12 deletions
diff --git a/doc/checkupdates.8.adoc b/doc/checkupdates.8.adoc
index 0991ef4..d4a2dba 100644
--- a/doc/checkupdates.8.adoc
+++ b/doc/checkupdates.8.adoc
@@ -20,6 +20,10 @@ updates with the old and new version.
Options
-------
+*-c, \--change*::
+ Check for new available updates only, prints the list of available updates
+ only if it differs from the last time checkupdates was run with that option.
+
*-d, \--download*::
Download any pending updates to the pacman cache.
@@ -27,17 +31,14 @@ Options
Display syntax and command-line options.
*\--nocolor*::
- Do not colorize output.
+ Do not colorize output. `Color` must be enabled in `pacman.conf` for the
+ listing to be colored to begin with.
*-n, \--nosync*::
Do not sync the temporary database, works best when the temporary database
is updated regularly through some other means such as a cronjob or systemd
timer.
-*-c, \--change*::
- Check for new available updates only, prints the list of available updates
- only if it differs from the last time checkupdates was run with that option.
-
*-V, \--version*::
Display version information.
diff --git a/src/checkupdates.sh.in b/src/checkupdates.sh.in
index 36a6d07..9526e41 100644
--- a/src/checkupdates.sh.in
+++ b/src/checkupdates.sh.in
@@ -24,7 +24,8 @@ declare -r myver='@PACKAGE_VERSION@'
LIBRARY=${LIBRARY:-'@libmakepkgdir@'}
DOWNLOAD_CACHE=0
-USE_COLOR='y'
+SYNC=1
+USE_COLOR=1
# Import libmakepkg
# shellcheck source=/dev/null
@@ -59,10 +60,11 @@ Safely print a list of pending updates.
Usage: ${myname} [options]
Options:
+ -c, --change print only when available updates differ from the last --change run
-d, --download download pending updates to the pacman cache
- --nocolor do not colorize output
+ --nocolor do not colorize output (listing color also dependent on Color
+ option in pacman.conf)
-n, --nosync do not sync the temporary database
- -c, --change print only when available updates differ from the last --change run
-h, --help display this help message and exit
-V, --version display version information and exit
@@ -89,13 +91,12 @@ fi
set -- "${OPTRET[@]}"
unset OPT_SHORT OPT_LONG OPTRET
-SYNC=1
while :; do
case $1 in
-d|--download)
DOWNLOAD_CACHE=1 ;;
--nocolor)
- USE_COLOR='n';;
+ USE_COLOR=0 ;;
-n|--nosync)
SYNC=0 ;;
-c|--change)
@@ -114,8 +115,13 @@ while :; do
done
# check if messages are to be printed using color
-if [[ -t 2 && $USE_COLOR != "n" ]]; then
+if [[ -t 2 ]] && (( USE_COLOR )); then
colorize
+
+ # check if pacman colors are to be kept in the updates array
+ if pacman-conf | grep -q Color; then
+ PACMAN_COLOR=1
+ fi
else
unset ALL_OFF BOLD BLUE GREEN RED YELLOW
fi
@@ -146,7 +152,12 @@ if (( SYNC )); then
die 'Cannot fetch updates'
fi
fi
-mapfile -t updates < <(pacman -Qu --dbpath "$CHECKUPDATES_DB" 2> /dev/null | grep -v '\[.*\]')
+
+if (( PACMAN_COLOR )); then
+ mapfile -t updates < <(pacman --color always -Qu --dbpath "$CHECKUPDATES_DB" 2> /dev/null | grep -v '\[.*\]')
+else
+ mapfile -t updates < <(pacman -Qu --dbpath "$CHECKUPDATES_DB" 2> /dev/null | grep -v '\[.*\]')
+fi
if (( ${#updates[@]} )); then
if (( CHANGE )); then