-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_utils.sh
112 lines (95 loc) · 1.59 KB
/
_utils.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
#!/bin/bash
color_reset=$(tput sgr0)
color_red=$(tput setaf 1)
color_green=$(tput setaf 2)
color_yellow=$(tput setaf 3)
e_pending() {
printf "${color_yellow}⚡️ %s...${color_reset}" "$@"
printf "\n"
}
e_failure() {
printf "${color_red}✕ %s${color_reset}" "$@"
printf "\n"
}
e_success() {
printf "${color_green}✔ %s${color_reset}" "$@"
printf "\n"
}
e_settled() {
printf "${color_yellow}✨ %s!${color_reset}" "$@"
printf "\n"
}
has_command() {
if [ $(type -P $1) ]; then
return 0
fi
return 1
}
test_command() {
if has_command $1; then
e_success "$1"
else
e_failure "$1"
fi
}
has_brew() {
if $(brew ls --versions $1 > /dev/null); then
return 0
fi
return 1
}
test_brew() {
if has_brew $1; then
e_success "$1"
else
e_failure "$1"
fi
}
has_path() {
local path="$@"
if [ -e "$HOME/$path" ]; then
return 0
fi
return 1
}
test_path() {
# local path=$(echo "$@" | sed 's:.*/::')
if has_path $1; then
# e_success "$path"
e_success "$1"
else
# e_failure "$path"
e_failure "$1"
fi
}
has_app() {
local name="$@"
if [ -e "/Applications/$name.app" ]; then
return 0
fi
return 1
}
test_app() {
if has_app $1; then
e_success "$1"
else
e_failure "$1"
fi
}
has_consent() {
if [[ "$REPLY" =~ ^[Yy]$ ]]; then
return 0
fi
return 1
}
get_consent() {
printf "❔ %s [y/n]:" "$@"
read -p " " -n 1
printf "\n"
}
if ! [[ "${OSTYPE}" == "darwin"* ]]; then
e_failure "Unsupported operating system (macOS only)"
exit 1
fi
# This will clear the prompt before each sourced file.
clear