Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
95b5bc4
commit 2f70176
Showing
1 changed file
with
9 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,81 +1,21 @@ | ||
#!/bin/bash | ||
# | ||
# Prints out all available information on installed homebrew packages. Does not | ||
# include packages installed via cask | ||
|
||
|
||
### Bash options | ||
# exit upon receiving a non-zero exit code | ||
set -e | ||
# enable debuging | ||
#set -x | ||
# upon attempt to use an unset variable, print error and exit | ||
set -u | ||
# fail on first command in pipeline that fails, not last | ||
#set -o pipefail | ||
|
||
|
||
### Logging functions | ||
# Usage: log "What to log" | ||
log () { | ||
printf "%b\n" "$(date +"%Y-%m-%dT%H:%M:%S%z") $*" | ||
} | ||
# Usage: verbose "What to log if VERBOSE is true" | ||
verbose () { | ||
if [[ "$VERBOSE" == "true" ]]; then | ||
log "$*" | ||
fi | ||
} | ||
# -- old version of script (not as useful IMO but kept around) -- | ||
#for pkg in $(brew list); do | ||
# brew info $pkg | ||
# echo | ||
#done | ||
|
||
|
||
# set script_dir to location this script is running in | ||
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" | ||
# set this here or can't use after getopts | ||
SCRIPT_NAME="$(basename $0)" | ||
# full command which can be printed out if needed | ||
SCRIPT_CMD="$*" | ||
|
||
|
||
### Option Handling | ||
# Defaults | ||
VERBOSE=${VERBOSE:-"false"} | ||
|
||
while getopts ":hv" opt; do | ||
case $opt in | ||
h) | ||
echo "Usage: $(basename $0) [OPTION] [filename]" | ||
echo 'Description of command' | ||
echo | ||
echo 'Options:' | ||
echo ' -h This help message' | ||
echo ' -v Be verbose' | ||
exit 0 | ||
;; | ||
v) | ||
VERBOSE=true | ||
;; | ||
\?) | ||
echo "Invalid option: -$OPTARG" >&2 | ||
exit 1 | ||
;; | ||
:) | ||
echo "Option -$OPTARG requires an argument" >&2 | ||
exit 1 | ||
;; | ||
esac | ||
done | ||
shift `expr $OPTIND - 1` | ||
verbose "Additional arguments after options: $*" | ||
|
||
|
||
### Actual script begins here | ||
for pkg in $(brew list); do | ||
brew info $pkg | ||
echo | ||
done | ||
|
||
|
||
|
||
# SECONDS is a bash builtin | ||
verbose "Script ran for ${SECONDS} seconds" | ||
# -- new version of script -- | ||
brew info --json=v1 --installed | python -m json.tool | ||
|
||
exit 0 | ||
|