forked from joshoohaah/dotfiles
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlib.sh
More file actions
157 lines (138 loc) · 3.59 KB
/
lib.sh
File metadata and controls
157 lines (138 loc) · 3.59 KB
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
#!/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_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
}
# npmlist=`npm list -g`
# function require_npm() {
# running "npm $1"
# echo $npmlist | grep $1@ > /dev/null
# if [[ $? != 0 ]]; then
# action "npm install -g $1"
# npm install -g $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_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 require_vagrant_plugin() {
running "vagrant plugin $1"
local vagrant_plugin=$1
local vagrant_plugin_version=$2
local grepExpect=$vagrant_plugin
local grepStatus=$(vagrant plugin list | grep $vagrant_plugin)
if [[ ! -z $vagrant_plugin_version ]]; then
grepExpect=$grepExpect' ('$vagrant_plugin_version')'
else
# we are only looking for the name
grepStatus=${grepStatus%% *}
fi
#echo 'checking if '$grepExpect' is installed via grepStatus: '$grepStatus
if [[ $grepStatus != $grepExpect ]];
then
action "installing vagrant plugin $1 $2"
if [[ ! -z $vagrant_plugin_version ]]; then
vagrant plugin install $vagrant_plugin --plugin-version $vagrant_plugin_version
else
vagrant plugin install $vagrant_plugin
fi
fi
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
}