2021-03-03 10:22:54 +00:00
|
|
|
#: * `--version`, `-v`
|
|
|
|
#:
|
|
|
|
#: Print the version numbers of Homebrew, Homebrew/homebrew-core and Homebrew/homebrew-cask (if tapped) to standard output.
|
|
|
|
|
2021-04-28 20:47:24 +09:00
|
|
|
# HOMEBREW_CORE_REPOSITORY, HOMEBREW_CASK_REPOSITORY, HOMEBREW_VERSION are set by brew.sh
|
|
|
|
# shellcheck disable=SC2154
|
2021-03-03 10:22:54 +00:00
|
|
|
version_string() {
|
|
|
|
local repo="$1"
|
2021-09-13 20:32:20 +08:00
|
|
|
if ! [[ -d "${repo}" ]]
|
|
|
|
then
|
2021-03-03 10:22:54 +00:00
|
|
|
echo "N/A"
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
|
|
|
|
local pretty_revision
|
2021-04-28 20:47:24 +09:00
|
|
|
pretty_revision="$(git -C "${repo}" rev-parse --short --verify --quiet HEAD)"
|
2021-09-13 20:32:20 +08:00
|
|
|
if [[ -z "${pretty_revision}" ]]
|
|
|
|
then
|
2021-03-03 10:22:54 +00:00
|
|
|
echo "(no Git repository)"
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
|
|
|
|
local git_last_commit_date
|
2021-09-13 20:32:20 +08:00
|
|
|
git_last_commit_date="$(git -C "${repo}" show -s --format='%cd' --date=short HEAD)"
|
2021-03-03 10:22:54 +00:00
|
|
|
echo "(git revision ${pretty_revision}; last commit ${git_last_commit_date})"
|
|
|
|
}
|
|
|
|
|
|
|
|
homebrew-version() {
|
2021-04-28 20:47:24 +09:00
|
|
|
echo "Homebrew ${HOMEBREW_VERSION}"
|
|
|
|
echo "Homebrew/homebrew-core $(version_string "${HOMEBREW_CORE_REPOSITORY}")"
|
2021-03-03 10:22:54 +00:00
|
|
|
|
2021-09-13 20:32:20 +08:00
|
|
|
if [[ -d "${HOMEBREW_CASK_REPOSITORY}" ]]
|
|
|
|
then
|
2021-04-28 20:47:24 +09:00
|
|
|
echo "Homebrew/homebrew-cask $(version_string "${HOMEBREW_CASK_REPOSITORY}")"
|
2021-03-03 10:22:54 +00:00
|
|
|
fi
|
|
|
|
}
|