-
Notifications
You must be signed in to change notification settings - Fork 36
/
rimerc.sh
executable file
·114 lines (93 loc) · 2.27 KB
/
rimerc.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
#!/usr/bin/env bash
RELEASE_PATH=release
if [ -z $1 ]; then
echo "Provide at least one input method!"
echo "Such as: $0 fcitx5"
exit
fi
VALID_RIME="fcitx, fcitx5, ibus, squirrel, trime or weasel"
case $1 in
fcitx)
RIME_CONFIG_PATH=~/.config/fcitx/rime
;;
fcitx5)
RIME_CONFIG_PATH=~/.local/share/fcitx5/rime
;;
ibus)
RIME_CONFIG_PATH=~/.config/ibus/rime
;;
squirrel)
RIME_CONFIG_PATH=~/Library/Rime
;;
trime | weasel)
case $1 in
weasel)
RIME_CONFIG_PATH=%AppData%\Rime
;;
trime)
RIME_CONFIG_PATH=/sdcard/rime
;;
esac
# package flavor
./script/package.sh $1
echo "Please install $1 manually"
echo "Copy ${RELEASE_PATH}/$1 to your rime $1 ${RIME_CONFIG_PATH} and deploy"
exit
;;
*)
echo "Invalid $1 input method"
echo "Valid input method is ${VALID_RIME}"
exit
;;
esac
echo -e "Starting setup $1...\n"
INPUT_METHOD=$1
RIMERC=rimerc
# package flavor
./script/package.sh $1
# check if input method installed
if [ $1 == squirrel ]; then
if [ ! -d '/Library/Input Methods/Squirrel.app' ]; then
echo "Please install ${INPUT_METHOD} in your macOS and try again!"
exit
fi
else
if ! command -v ${INPUT_METHOD} &>/dev/null; then
echo "${INPUT_METHOD} could not be found"
echo "Please install ${INPUT_METHOD} in your distro and try again!"
exit
fi
fi
# backup rime config
if [ -d ${RIME_CONFIG_PATH} ]; then
BACKUP_PATH=$(mktemp -p $(dirname ${RIME_CONFIG_PATH}) -d \
-t ${RIMERC}-backup-$(date '+%Y%m%d')-XXXX)
mv ${RIME_CONFIG_PATH}/* ${BACKUP_PATH}
echo -e "\nBackup your rime config to ${BACKUP_PATH}"
fi
# copy config to config path
mkdir -p ${RIME_CONFIG_PATH}
cp -a ${RELEASE_PATH}/${INPUT_METHOD}/* ${RIME_CONFIG_PATH}
# copy userdb to config path
cp -a ${BACKUP_PATH}/*.userdb ${RIME_CONFIG_PATH}
# restart input method
echo -e "\nWaiting for ${INPUT_METHOD} restart and deploying..."
case ${INPUT_METHOD} in
fcitx | fcitx5)
nohup ${INPUT_METHOD} -r >/dev/null 2>&1 &
;;
ibus)
nohup ${INPUT_METHOD} restart >/dev/null 2>&1 &
;;
squirrel)
RED='\033[0;31m'
CLEAR='\033[0m'
echo -e "${RED}Please deploy ${INPUT_METHOD} manually!${CLEAR}"
;;
*)
echo "Invalid ${INPUT_METHOD} input method"
echo "Valid input method is ${VALID_RIME}"
exit
;;
esac
echo -e "\nSetup rimerc successfully!"