Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions cmd/brew-list-pkg-ids-by-regexp
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#: * `list-pkg-ids-by-regexp` <regexp>
#:
#: Print pkg receipt IDs for installed packages matching a regular
#: expression, which may be useful in a Cask uninstall stanza, eg
#:
#: uninstall pkgutil: "pkg.regexp.goes.here"
#:
#: Unlike most other scripts in this directory, package IDs attributed to
#: Apple are NOT excluded from the output. This is to avoid uninstalling
#: essential system files due to an exuberant regexp.
#:
#: For more information, see
#:
#: https://github.com/Homebrew/homebrew-cask/blob/HEAD/doc/cask_language_reference/stanzas/uninstall.md
#:
#: -h, --help Show this message.

set -e # exit on any uncaught error
set +o histexpand # don't expand history expressions
shopt -s nocasematch # case-insensitive regular expressions

warn() {
local message="$@"
message="${message//\\t/$'\011'}"
message="${message//\\n/$'\012'}"
message="${message%"${message##*[![:space:]]}"}"
printf "%s\n" "$message" 1>&2
}

die() {
warn "$@"
exit 1
}

fail_informatively() {
local message="No match."
if ! [[ "$1" =~ '*' ]]; then
message="$message Suggestion: try '${1}.*'"
fi
die "$message"
}

analyze_regexp() {
if [[ "$1" =~ ^\^ ]]; then
warn "Note: pkgutil regular expressions are implicitly anchored with '^' at start"
fi
if [[ "$1" =~ \$$ ]]; then
warn "Note: pkgutil regular expressions are implicitly anchored with '$' at end"
fi
}

_list_pkg_ids_by_regexp() {
analyze_regexp "$1"
if ! /usr/sbin/pkgutil --pkgs="$1"; then
fail_informatively "$1"
fi
}

_list_pkg_ids_by_regexp "${@}"
83 changes: 0 additions & 83 deletions developer/bin/list_pkg_ids_by_regexp

This file was deleted.

Loading