-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommon.sh
59 lines (50 loc) · 1.08 KB
/
common.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# shellcheck shell=bash disable=SC2034
# bootstrap a common and minimal environment for scripts
# common variables
DONE_MSG="$GREEN$BOLD d o n e$RESET"
MJS_COMMON_ENV=1
# check whether first argument is a command
exists() {
command -v "$1" &> /dev/null
}
# check whether homebrew is installed
has_brew() {
exists brew
}
# check whether a cask is installed
brew_cask_installed() {
grep -Fqsx "$1" <(brew list -1 --cask)
}
# install a cask
brew_cask_install() {
if brew_cask_installed "$1"; then
echo -e "$BLUE$1$RESET is already installed."
else
brew cask install "$1"
fi
}
# check whether a formula is installed
brew_installed() {
grep -Fqsx "$1" <(brew list -1)
}
# install a homebrew formula
brew_install() {
local formula=$1
if brew_installed "$formula"; then
echo -e "$BLUE$formula$RESET is already installed."
else
brew install "$@"
fi
}
# check whether a tap is tapped
brew_tapped() {
grep -Fqsx "$1" <(brew tap)
}
# tap a homebrew tap
brew_tap() {
if brew_tapped "$1"; then
echo -e "$BLUE$1$RESET is already tapped."
else
brew tap "$1"
fi
}