-
Notifications
You must be signed in to change notification settings - Fork 0
/
helpers.sh
129 lines (107 loc) · 2.56 KB
/
helpers.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#!/usr/bin/env bash
# variables
ROOT=$(pwd)
# Colors
ESC_SEQ="\x1b["
COL_RESET=$ESC_SEQ"39;49;00m"
COL_RED=$ESC_SEQ"31;01m"
COL_GREEN=$ESC_SEQ"32;01m"
COL_YELLOW=$ESC_SEQ"33;01m"
COL_BLUE=$ESC_SEQ"34;01m"
COL_MAGENTA=$ESC_SEQ"35;01m"
COL_CYAN=$ESC_SEQ"36;01m"
function ok() {
echo -e "$COL_GREEN[ok]$COL_RESET "$1
}
function bot() {
echo -e "\n$COL_GREEN[._.]$COL_RESET - "$1
}
function running() {
echo -en "$COL_YELLOW ⇒ $COL_RESET"$1"\n"
}
function action() {
echo -e "\n$COL_YELLOW[action]:$COL_RESET\n ⇒ $1..."
}
function warn() {
echo -e "$COL_YELLOW[warning]$COL_RESET "$1
}
function error() {
echo -e "$COL_RED[error]$COL_RESET "$1
}
ask() {
# https://gist.github.com/davejamesmiller/1965569
local prompt default reply
if [ "${2:-}" = "Y" ]; then
prompt="Y/n"
default=Y
elif [ "${2:-}" = "N" ]; then
prompt="y/N"
default=N
else
prompt="y/n"
default=
fi
while true; do
# Ask the question (not using "read -p" as it uses stderr not stdout)
echo -n "$1 [$prompt] "
# Read the answer (use /dev/tty in case stdin is redirected from somewhere else)
read reply </dev/tty
# Default?
if [ -z "$reply" ]; then
reply=$default
fi
# Check if the reply is valid
case "$reply" in
Y*|y*) return 0 ;;
N*|n*) return 1 ;;
esac
done
}
say() {
echo "$1"
}
function cask_install() {
action "brew install --cask $1 $2"
brew install --cask $1 > /dev/null 2>&1
if [[ $? != 0 ]]; then
error "failed to install $1! skipping..."
else
ok
fi
}
function brew_install() {
action "brew install $1 $2"
brew install $1 $2 > /dev/null 2>&1
if [[ $? != 0 ]]; then
error "failed to install $1! skipping..."
else
ok
fi
}
function service_start() {
action "brew services start $1 $2"
brew services start $1 $2 > /dev/null 2>&1
if [[ $? != 0 ]]; then
error "failed to start $1! skipping..."
else
ok
fi
}
function brew_link() {
action "brew link --force $1"
brew services start $1 > /dev/null 2>&1
if [[ $? != 0 ]]; then
error "failed to force link $1! skipping..."
else
ok
fi
}
function composer_global() {
action "composer global require $1 $2"
composer global require $1 $2 > /dev/null 2>&1
if [[ $? != 0 ]]; then
error "failed to install $1 globally! skipping..."
else
ok
fi
}