[PATCH 1/2] checkupdates: add -q/--quiet
diff --git a/src/checkupdates.sh.in b/src/checkupdates.sh.in index 0885983..024243c 100644 --- a/src/checkupdates.sh.in +++ b/src/checkupdates.sh.in @@ -22,6 +22,7 @@ declare -r myname='checkupdates' declare -r myver='@PACKAGE_VERSION@' DOWNLOAD_CACHE=0 +QUIET=0 m4_include(../lib/output_format.sh) m4_include(../lib/term_colors.sh) @@ -38,14 +39,15 @@ Usage: ${myname} [options] Options: -d, --download download pending updates to the pacman cache. -h, --help display this help message and exit. + -q, --quiet only display pkgnames. Note: Export the "CHECKUPDATES_DB" variable to change the path of the temporary database. __EOF__ } -OPT_SHORT='dh' -OPT_LONG=('download' 'help') +OPT_SHORT='dhq' +OPT_LONG=('download' 'help' 'quiet') if ! parseopts "$OPT_SHORT" "${OPT_LONG[@]}" -- "$@"; then exit 1 @@ -60,6 +62,8 @@ while :; do -h|--help) usage exit 0 ;; + -q|--quiet) + QUIET=1 ;; --) shift break ;; @@ -92,6 +96,9 @@ fi mapfile -t updates < <(pacman -Qu --dbpath "$CHECKUPDATES_DB" 2> /dev/null | grep -v '\[.*\]') if (( ${#updates[@]} )); then + if (( $QUIET )); then + updates=("${updates[@]%% *}") + fi printf '%s\n' "${updates[@]}" if (( DOWNLOAD_CACHE )); then sudo pacman -Sw --noconfirm "${updates[@]%% *}" --dbpath "$CHECKUPDATES_DB" --logfile /dev/null -- 2.22.0
diff --git a/src/checkupdates.sh.in b/src/checkupdates.sh.in index 024243c..ae8197c 100644 --- a/src/checkupdates.sh.in +++ b/src/checkupdates.sh.in @@ -34,7 +34,7 @@ ${myname} v${myver} Safely print a list of pending updates -Usage: ${myname} [options] +Usage: ${myname} [options] [targets...] Options: -d, --download download pending updates to the pacman cache. @@ -93,7 +93,7 @@ if ! fakeroot -- pacman -Sy --dbpath "$CHECKUPDATES_DB" --logfile /dev/null &> / error 'Cannot fetch updates' exit 1 fi -mapfile -t updates < <(pacman -Qu --dbpath "$CHECKUPDATES_DB" 2> /dev/null | grep -v '\[.*\]') +mapfile -t updates < <(pacman -Qu --dbpath "$CHECKUPDATES_DB" -- "$@" 2> /dev/null | grep -v '\[.*\]') if (( ${#updates[@]} )); then if (( $QUIET )); then -- 2.22.0
On 6/28/19 4:12 PM, morganamilo wrote: What would this be used by? When do people want to only know when there are *some* updates? -- Eli Schwartz Bug Wrangler and Trusted User
On 6/28/19 4:12 PM, morganamilo wrote: What's the utility of adding this extra option, vs. just using: checkupdates | awk '{print $1}' The typical use of this script probably just cares about the exit code anyway. There are some scripts which just count the number of lines. -- Eli Schwartz Bug Wrangler and Trusted User
participants (2)
-
Eli Schwartz
-
morganamilo