forked from atomantic/dotfiles
-
Notifications
You must be signed in to change notification settings - Fork 1
/
lib.sh
162 lines (142 loc) · 3.34 KB
/
lib.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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
#!/usr/bin/env bash
###
# some bash library helpers
# @author Adam Eivy
###
# 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": "
}
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
}
function require_cask() {
running "brew cask $1"
brew cask list $1 > /dev/null 2>&1 | true
if [[ ${PIPESTATUS[0]} != 0 ]]; then
action "brew cask install $1 $2"
brew cask install $1
if [[ $? != 0 ]]; then
error "failed to install $1! aborting..."
# exit -1
fi
fi
ok
}
function require_brew() {
running "brew $1 $2"
brew list $1 > /dev/null 2>&1 | true
if [[ ${PIPESTATUS[0]} != 0 ]]; then
action "brew install $1 $2"
brew install $1 $2
if [[ $? != 0 ]]; then
error "failed to install $1! aborting..."
# exit -1
fi
fi
ok
}
function require_pip() {
running "pip $1"
if [[ $(pip list | grep $1 | head -1 | cut -d' ' -f1) != $1 ]];
then
action "pip install $1"
pip install $1
fi
ok
}
function require_node(){
running "node -v"
node -v
if [[ $? != 0 ]]; then
action "node not found, installing via homebrew"
brew install node
fi
ok
}
function require_gem() {
running "gem $1"
if [[ $(gem list --local | grep $1 | head -1 | cut -d' ' -f1) != $1 ]];
then
action "gem install $1"
gem install $1
fi
ok
}
function require_npm() {
sourceNVM
nvm use stable
running "npm $1"
npm list -g --depth 0 | grep $1@ > /dev/null
if [[ $? != 0 ]]; then
action "npm install -g $1"
npm install -g $1
fi
ok
}
function require_apm() {
running "checking atom plugin: $1"
apm list --installed --bare | grep $1@ > /dev/null
if [[ $? != 0 ]]; then
action "apm install $1"
apm install $1
fi
ok
}
function sourceNVM(){
export NVM_DIR=~/.nvm
source $(brew --prefix nvm)/nvm.sh
}
function require_nvm() {
mkdir -p ~/.nvm
cp $(brew --prefix nvm)/nvm-exec ~/.nvm/
sourceNVM
nvm install $1
if [[ $? != 0 ]]; then
action "installing nvm"
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.25.4/install.sh | bash
. ~/.bashrc
nvm install $1
fi
nvm use $1
ok
}
function symlinkifne {
running "$1"
if [[ -e $1 ]]; then
# file exists
if [[ -L $1 ]]; then
# it's already a simlink (could have come from this project)
echo -en '\tsimlink exists, skipped\t';ok
return
fi
# backup file does not exist yet
if [[ ! -e ~/.dotfiles_backup/$1 ]];then
mv $1 ~/.dotfiles_backup/
echo -en 'backed up saved...';
fi
fi
# create the link
ln -s ~/.dotfiles/$1 $1
echo -en '\tlinked';ok
}