-
Notifications
You must be signed in to change notification settings - Fork 0
/
helpers.sh
107 lines (88 loc) · 1.68 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
#!/bin/bash
# Adds support for newer versions of Mac OSX that do not support the \e
# escape sequence
if [ "$(uname)" == "Darwin" ]; then
__ESCAPESEQ="\x1b"
elif [ "$(expr substr $(uname -s) 1 5)" == "Linux" ]; then
__ESCAPESEQ="\e"
fi
# -- COLORS -----------------------------------------------------------------------
function __colortext()
{
echo -e " $__ESCAPESEQ[$2m$1$__ESCAPESEQ[0m"
}
function echogreen()
{
echo $(__colortext "$1" "32")
}
function echored()
{
echo $(__colortext "$1" "31")
}
function echoblue()
{
echo $(__colortext "$1" "34")
}
function echopurple()
{
echo $(__colortext "$1" "35")
}
function echoyellow()
{
echo $(__colortext "$1" "33")
}
function echocyan()
{
echo $(__colortext "$1" "36")
}
# -- HELPERS -----------------------------------------------------------------------
exists() {
type "$1" >/dev/null 2>/dev/null
}
echo_header() {
echo " === $1 ==="
}
echo_item() {
if [ "$2" == "green" ]; then
echogreen "---> $1"
elif [ "$2" == "red" ]; then
echored "---> $1"
else
echo "---> $1"
fi
}
function symlink_file() {
local source=$1
local dest=$2
local message=${3:-"Symlinking"}
echo_item "$message" "green"
ln -sf "$source" "$dest"
}
function create_directory() {
local dir=$1
mkdir -p "$dir"
}
get_boolean_response() {
while true; do
read -p "$1 (Y/N) " yn
case $yn in
[Yy]* ) return 0;;
[Nn]* ) return 1;;
* ) echo "Please answer yes or no";;
esac
done
}
system_is_OSX() {
if [ "$(uname)" == "Darwin" ]; then
return 0
else
return 1
fi
}
system_is_linux() {
if [ "$(expr $(uname -s) : '\(Linux\)')" ]; then
return 0
else
return 1
fi
}