-
-
Notifications
You must be signed in to change notification settings - Fork 9.3k
/
--version.sh
40 lines (34 loc) 路 1.12 KB
/
--version.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#: * `--version`, `-v`
#:
#: Print the version numbers of Homebrew, Homebrew/homebrew-core and Homebrew/homebrew-cask (if tapped) to standard output.
# HOMEBREW_CORE_REPOSITORY, HOMEBREW_CASK_REPOSITORY, HOMEBREW_VERSION are set by brew.sh
# shellcheck disable=SC2154
version_string() {
local repo="$1"
if ! [[ -d "${repo}" ]]
then
echo "N/A"
return
fi
local pretty_revision
pretty_revision="$(git -C "${repo}" rev-parse --short --verify --quiet HEAD)"
if [[ -z "${pretty_revision}" ]]
then
echo "(no Git repository)"
return
fi
local git_last_commit_date
git_last_commit_date="$(git -C "${repo}" show -s --format='%cd' --date=short HEAD)"
echo "(git revision ${pretty_revision}; last commit ${git_last_commit_date})"
}
homebrew-version() {
echo "Homebrew ${HOMEBREW_VERSION}"
if [[ -n "${HOMEBREW_NO_INSTALL_FROM_API}" || -d "${HOMEBREW_CORE_REPOSITORY}" ]]
then
echo "Homebrew/homebrew-core $(version_string "${HOMEBREW_CORE_REPOSITORY}")"
fi
if [[ -d "${HOMEBREW_CASK_REPOSITORY}" ]]
then
echo "Homebrew/homebrew-cask $(version_string "${HOMEBREW_CASK_REPOSITORY}")"
fi
}