-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathinstaller
executable file
·268 lines (218 loc) · 6.1 KB
/
installer
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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
#!/usr/bin/env bash
CONFIG_DIR="$HOME/.hammerspoon"
SPOONS_DIR="$CONFIG_DIR/Spoons"
ask() {
print_question "$1"
read -r
}
print_question() {
printf "$(tput setaf 3) [?] $1$(tput sgr0)"
}
get_answer() {
printf "%s" "$REPLY"
}
dotheader() {
echo
dotsay "@b@green[[$1]]"
echo
}
dotsay() {
local result=$(_colorized $@)
echo "$result"
}
saysuccess() {
printf " "
dotsay "✅ @blue[[$1]]"
}
sayinfo() {
printf " "
dotsay "+ @yellow[[$1]]"
}
indent() {
sed 's/^/ /'
}
_colorized() {
echo "$@" | sed -E \
-e 's/((@(red|green|yellow|blue|magenta|cyan|white|reset|b|u))+)[[]{2}(.*)[]]{2}/\1\4@reset/g' \
-e "s/@red/$(tput setaf 1)/g" \
-e "s/@green/$(tput setaf 2)/g" \
-e "s/@yellow/$(tput setaf 3)/g" \
-e "s/@blue/$(tput setaf 4)/g" \
-e "s/@magenta/$(tput setaf 5)/g" \
-e "s/@cyan/$(tput setaf 6)/g" \
-e "s/@white/$(tput setaf 7)/g" \
-e "s/@reset/$(tput sgr0)/g" \
-e "s/@b/$(tput bold)/g" \
-e "s/@u/$(tput sgr 0 1)/g"
}
function command_exists() {
local name=$1
command -v "$name" >/dev/null 2>&1
}
function warn_about_xcode_tools() {
dotsay "@b@yellow[[WARNING]]: If you don't have XCode tools \
installed/enabled, you're going to have a bad time with this script, so do \
that first."
echo
printf "Sleeping for 3 seconds then continuing with install"
sleep 1
printf "."
sleep 1
printf "."
sleep 1
printf "."
echo
echo
}
function check_for_brew() {
if ! command_exists brew; then
dotsay "@b@red[[Homebrew not found - please install it first]]"
exit 1
fi
}
function install_hammerspoon() {
if [ -d "/Applications/Hammerspoon.app" ]; then
saysuccess "Hammerspoon is already installed!"
else
sayinfo "Hammerspoon not found, installing..."
brew install --cask hammerspoon | indent
fi
}
function bootstrap_hammerspoon_directory() {
if [ ! -d "$CONFIG_DIR" ]; then
sayinfo "Creating $CONFIG_DIR directory"
mkdir -p $CONFIG_DIR
else
saysuccess "$CONFIG_DIR exists!"
fi
}
function bootstrap_spoons_dir() {
if [ ! -d "$SPOONS_DIR" ]; then
sayinfo "Creating $SPOONS_DIR"
mkdir -p $SPOONS_DIR
sayinfo "Adding a .gitignore file to $SPOONS_DIR for your dotfiles"
touch $SPOONS_DIR/.gitignore
cat << EOF | tee -a "$SPOONS_DIR/.gitignore" > /dev/null
*
!.gitignore
!SpoonInstall.spoon
EOF
else
saysuccess "$SPOONS_DIR already exists"
fi
}
function bootstrap_spoon_install() {
local url="https://github.com/Hammerspoon/Spoons/raw/master/Spoons/SpoonInstall.spoon.zip"
local destination=/tmp/SpoonInstall.spoon.zip
local spoons_dir=$HOME/.hammerspoon/Spoons
if [ ! -d "$SPOONS_DIR/SpoonInstall.spoon" ]; then
sayinfo "Installing SpoonInstall.spoon in $SPOONS_DIR"
wget -nv $url -O $destination | indent
unzip -d $SPOONS_DIR $destination | indent
else
saysuccess "SpoonInstall.spoon already setup"
fi
}
function bootstrap_vim_mode_spoon() {
local dir="$SPOONS_DIR/VimMode.spoon"
if [ -d "$dir" ]; then
saysuccess "VimMode.spoon is already installed!"
else
sayinfo "Cloning VimMode.spoon from Git"
echo
git clone https://github.com/dbalatero/VimMode.spoon "$dir" | indent
echo
fi
sayinfo "Checking out master branch"
echo
local current_dir=$(pwd)
cd $dir && (git checkout master 2>/dev/null | indent)
echo
sayinfo "Pulling latest changes"
echo
cd $dir && (git pull origin master 2>/dev/null | indent)
echo
cd $current_dir
}
function bootstrap_init_lua() {
local init_file="$CONFIG_DIR/init.lua"
if [ ! -f "$init_file" ]; then
sayinfo "Setting up $init_file"
echo 'hs.loadSpoon("SpoonInstall")' > "$init_file"
else
saysuccess "$init_file exists!"
fi
if ! grep -q "VimMode" "$init_file"; then
sayinfo "Patching $init_file with Vim init code"
cat << EOF | tee -a "$init_file" > /dev/null
--------------------------------
-- START VIM CONFIG
--------------------------------
local VimMode = hs.loadSpoon("VimMode")
local vim = VimMode:new()
-- Configure apps you do *not* want Vim mode enabled in
-- For example, you don't want this plugin overriding your control of Terminal
-- vim
vim
:disableForApp('Code')
:disableForApp('zoom.us')
:disableForApp('iTerm')
:disableForApp('iTerm2')
:disableForApp('Terminal')
-- If you want the screen to dim (a la Flux) when you enter normal mode
-- flip this to true.
vim:shouldDimScreenInNormalMode(false)
-- If you want to show an on-screen alert when you enter normal mode, set
-- this to true
vim:shouldShowAlertInNormalMode(true)
-- You can configure your on-screen alert font
vim:setAlertFont("Courier New")
-- Enter normal mode by typing a key sequence
vim:enterWithSequence('jk')
-- if you want to bind a single key to entering vim, remove the
-- :enterWithSequence('jk') line above and uncomment the bindHotKeys line
-- below:
--
-- To customize the hot key you want, see the mods and key parameters at:
-- https://www.hammerspoon.org/docs/hs.hotkey.html#bind
--
-- vim:bindHotKeys({ enter = { {'ctrl'}, ';' } })
--------------------------------
-- END VIM CONFIG
--------------------------------
EOF
else
saysuccess "VimMode init code already exists in $init_file"
fi
}
function restart_hammerspoon() {
killall Hammerspoon >/dev/null 2>&1
open -a Hammerspoon
}
check_for_brew
warn_about_xcode_tools
dotheader "Checking for Hammerspoon..."
install_hammerspoon
dotheader "Setting up Hammerspoon config directory..."
bootstrap_hammerspoon_directory
bootstrap_spoons_dir
dotheader "Adding SpoonInstall.spoon if necessary for package management"
bootstrap_spoon_install
dotheader "Downloading VimMode.spoon"
bootstrap_vim_mode_spoon
dotheader "Setting up ~/.hammerspoon/init.lua"
bootstrap_init_lua
dotheader "Restarting Hammerspoon"
restart_hammerspoon
echo
saysuccess "Install complete"
echo
dotsay "💁♂️ @b@yellow[[Important post-install info]]"
echo
dotsay "- To change your configuration settings, edit @b@blue[[~/.hammerspoon/init.lua]]"
dotsay "- In the Mac menu bar, open Hammerspoon preferences and set:"
printf " "
dotsay " + @b@blue[[Enable Accessibility]]"
printf " "
dotsay " + @b@blue[[Launch Hammerspoon at login]]"
echo