-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.sh
executable file
·105 lines (85 loc) · 3.01 KB
/
setup.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
#!/usr/bin/env bash
RED="\033[0;31m"
GREEN="\033[0;32m"
YELLOW="\033[0;33m"
BLUE="\033[0;36m"
NORMAL="\033[0m"
HAMMERSPOON_REPO_HTTPS="https://github.com/luismayta/hammerspoon.git"
HAMMERSPOON_REPO_BRANCH="develop"
HAMMERSPOON_ROOT_PATH="${HOME}/.hammerspoon"
HAMMERSPOON_MESSAGE_BREW="Please install brew or use antibody bundle luismayta/zsh-brew branch:develop"
HAMMERSPOON_MESSAGE_DONE="Keep calm and use Hammerspoon!"
HAMMERSPOON_BACKUP_PATH="${HOME}/.backup"
message_error() {
printf "${RED}%s${NORMAL}\n" "[ERROR]: ${1}"
return 0
}
message_info() {
printf "${BLUE}%s${NORMAL}\n" "[INFO]: ${1}"
}
message_warning() {
printf "${YELLOW}%s${NORMAL}\n" "[WARNING]: ${1}"
}
message_success() {
printf "${GREEN}%s${NORMAL}\n" "🍺️ [SUCCESS]: ${1}"
}
hammerspoon::install::dependences() {
if ! type -p brew > /dev/null; then
message_warning "${HAMMERSPOON_MESSAGE_BREW}"
return 0
fi
hash git >/dev/null 2>&1 || {
brew install git
}
hash curl >/dev/null 2>&1 || {
brew install curl
}
hash wget >/dev/null 2>&1 || {
brew install wget
}
hash yarn >/dev/null 2>&1 || {
brew install yarn
}
hash do-not-disturb-cli >/dev/null 2>&1 || {
if type -p yarn > /dev/null; then
yarn global add do-not-disturb-cli
return
fi
}
}
# hammerspoon::install - install hammerspoon app
hammerspoon::install() {
if ! type -p brew > /dev/null; then
message_warning "${HAMMERSPOON_MESSAGE_BREW}"
return
fi
message_info "Install Hammerspoon"
brew install --cask hammerspoon
message_success "Installed Hammerspoon"
}
# hammerspoon::post_install - post install hammerspoon settings
hammerspoon::post_install() {
message_info "Looking for an existing hammerspoon config..."
if [ -d "${HAMMERSPOON_ROOT_PATH}" ]; then
message_warning "Found ${HAMMERSPOON_ROOT_PATH}"
message_info "You will see your old ${HAMMERSPOON_ROOT_PATH} as ${HAMMERSPOON_BACKUP_PATH}/hammerspoon.bak"
mkdir -p "${HAMMERSPOON_BACKUP_PATH}"
mv "${HAMMERSPOON_ROOT_PATH}" "${HAMMERSPOON_BACKUP_PATH}/hammerspoon.bak"
fi
# Prevent the cloned repository from having insecure permissions. Failing to do
# so causes compinit() calls to fail with "command not found: compdef" errors
# for users with insecure umasks (e.g., "002", allowing group writability). Note
# that this will be ignored under Cygwin by default, as Windows ACLs take
# precedence over umasks except for filesystems mounted with option "noacl".
umask g-w,o-w
message_info "Cloning hammerspoon from ${HAMMERSPOON_REPO_HTTPS}"
env git clone --depth=1 "${HAMMERSPOON_REPO_HTTPS}" --branch "${HAMMERSPOON_REPO_BRANCH}" "${HAMMERSPOON_ROOT_PATH}" || {
message_warning "git clone of hammerspoon repo failed."
return
}
message_info "${HAMMERSPOON_MESSAGE_DONE}"
}
if [ ! -d "/Applications/Hammerspoon.app" ]; then
hammerspoon::install
fi
hammerspoon::post_install