-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathinstall.sh
executable file
·96 lines (73 loc) · 1.63 KB
/
install.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
#!/bin/sh
set -e
# Default settings
DIR=${DIR:-~/.quiet_input_method}
REPO=${REPO:-Yufeikang/quiet_input_method}
REMOTE=${REMOTE:-https://github.com/${REPO}.git}
BRANCH=${BRANCH:-master}
command_exists() {
command -v "$@" >/dev/null 2>&1
}
fmt_error() {
echo ${RED}"Error: $@" >&2
}
fmt_underline() {
echo "$(printf '\033[4m')$@$(printf '\033[24m')"
}
fmt_code() {
echo "\`$(printf '\033[38;5;247m')$@\`"
}
setup_color() {
# Only use colors if connected to a terminal
if [ -t 1 ]; then
RED=$(printf '\033[31m')
GREEN=$(printf '\033[32m')
YELLOW=$(printf '\033[33m')
BLUE=$(printf '\033[34m')
BOLD=$(printf '\033[1m')
RESET=$(printf '\033[m')
else
RED=""
GREEN=""
YELLOW=""
BLUE=""
BOLD=""
RESET=""
fi
}
setup_src() {
umask g-w,o-w
echo "${BLUE}Cloning ..."
command_exists git || {
fmt_error "git is not installed"
exit 1
}
git clone -c core.eol=lf -c core.autocrlf=false \
-c fsck.zeroPaddedFilemode=ignore \
-c fetch.fsck.zeroPaddedFilemode=ignore \
-c receive.fsck.zeroPaddedFilemode=ignore \
--depth=1 --branch "$BRANCH" "$REMOTE" "$DIR" || {
fmt_error "git clone of repo failed"
exit 1
}
echo
}
setup_launch() {
sed -e "s/SRC_DIR/${DIR//\//\\/}/g" $DIR/launch.plist > ~/Library/LaunchAgents/quiet_input_method.plist
launchctl load ~/Library/LaunchAgents/quiet_input_method.plist
}
build() {
echo "${BLUE}Building ..."
xcrun -sdk macosx swiftc $DIR/run.swift -o $DIR/quiet
}
main() {
setup_color
if [ -d "$DIR" ]; then
echo "${YELLOW}The \$DIR folder already exists ($DIR)"
fi
setup_src
build
setup_launch
printf "$GREEN"
}
main "$@"