From 0e6018c6612e6f47fb91f2f16f2653848a6928f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADtor=20Galv=C3=A3o?= Date: Tue, 21 May 2019 02:07:31 +0100 Subject: [PATCH] list_recent_pkg_ids: updated script aesthetics --- developer/bin/list_recent_pkg_ids | 54 ++++++++++--------------------- 1 file changed, 17 insertions(+), 37 deletions(-) diff --git a/developer/bin/list_recent_pkg_ids b/developer/bin/list_recent_pkg_ids index 0c203ec26c..4d3d53b720 100755 --- a/developer/bin/list_recent_pkg_ids +++ b/developer/bin/list_recent_pkg_ids @@ -1,46 +1,26 @@ #!/bin/bash -# -# list_recent_pkg_ids -# -### -### settings -### +readonly program="$(basename "${0}")" -set -e # exit on any uncaught error -set +o histexpand # don't expand history expressions -shopt -s nocasematch # case-insensitive regular expressions +function usage { + echo " + List pkg receipt IDs for the 10 most recently installed packages. Package IDs attributed to Apple are excluded from the output. -### -### main -### + Usage: + ${program} [options] -_list_recent_pkg_ids () { - /bin/ls -t /var/db/receipts | \ - /usr/bin/egrep '\.plist$' | \ - /usr/bin/perl -pe 's{\A([^/]+)\.plist\Z}{$1}sg' | \ - /usr/bin/egrep -v '^com\.apple\.' | \ - /usr/bin/head -10 + Options: + -h, --help Show this message. + " | sed -E 's/ {4}//' } -# process args -if [[ $1 =~ ^-+h(elp)?$ ]]; then - printf "list_recent_pkg_ids - -Print pkg receipt IDs for the 10 most-recently-installed packages, -which may be useful in a Cask uninstall stanza, eg - - uninstall pkgutil: 'pkg.receipt.id.goes.here' - -Package IDs attributed to Apple are excluded from the output. - -See CONTRIBUTING.md for more information. - -" - exit +if [[ "${1}" =~ ^(-h|--help)$ ]]; then + usage + exit 0 fi -# dispatch main -_list_recent_pkg_ids "${@}" - -# +/bin/ls -t /var/db/receipts | \ + /usr/bin/grep '\.plist$' | \ + /usr/bin/grep --invert-match '^com\.apple\.' | \ + /usr/bin/sed 's/\.plist$//' | \ + /usr/bin/head -10