forked from chxuan/vimplus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
update.sh
executable file
·166 lines (142 loc) · 3.47 KB
/
update.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
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
#!/bin/bash
# 判断文件是否存在
function is_exist_file()
{
filename=$1
if [ -f $filename ]; then
echo 1
else
echo 0
fi
}
# 更新mac平台字体
function update_fonts_on_mac()
{
rm -rf ~/Library/Fonts/Droid\ Sans\ Mono\ Nerd\ Font\ Complete.otf
cp ./fonts/Droid\ Sans\ Mono\ Nerd\ Font\ Complete.otf ~/Library/Fonts
}
# 更新android平台字体
function update_fonts_on_android()
{
rm -rf ~/.termux/font.ttf
mkdir ~/.termux
cp ./fonts/DejaVu.ttf ~/.termux/font.ttf
# 刷新style
REL="am broadcast --user 0 -a com.termux.app.reload_style com.termux"
$REL > /dev/null
}
# 更新linux平台字体
function update_fonts_on_linux()
{
mkdir -p ~/.local/share/fonts
rm -rf ~/.local/share/fonts/Droid\ Sans\ Mono\ Nerd\ Font\ Complete.otf
cp ./fonts/Droid\ Sans\ Mono\ Nerd\ Font\ Complete.otf ~/.local/share/fonts
fc-cache -vf ~/.local/share/fonts
}
# 更新vim插件
function update_vim_plugin()
{
vim -c "PlugUpdate" -c "q" -c "q"
}
# 拷贝文件
function copy_files()
{
rm -rf ~/.vimrc
ln -s ${PWD}/.vimrc ~
vimrc_plugins=$HOME"/.vimrc.custom.plugins"
is_exist=$(is_exist_file $vimrc_plugins)
if [ $is_exist != 1 ]; then
cp ${PWD}/.vimrc.custom.plugins ~
fi
vimrc_config=$HOME"/.vimrc.custom.config"
is_exist=$(is_exist_file $vimrc_config)
if [ $is_exist != 1 ]; then
cp ${PWD}/.vimrc.custom.config ~
fi
rm -rf ~/.ycm_extra_conf.py
ln -s ${PWD}/.ycm_extra_conf.py ~
rm -rf ~/.vim/colors
ln -s ${PWD}/colors ~/.vim
rm -rf ~/.vim/ftplugin
ln -s ${PWD}/ftplugin ~/.vim
rm -rf ~/.vim/autoload
ln -s ${PWD}/autoload ~/.vim
}
# 打印logo
function print_logo()
{
color="$(tput setaf 6)"
normal="$(tput sgr0)"
printf "${color}"
echo ' __ __ '
echo '__ __/_/___ ___ ____ / /_ _______ '
echo '\ \ / / / __ `__ \/ __ \/ / / / / ___/ '
echo ' \ V / / / / / / / /_/ / / /_/ (__ ) '
echo ' \_/_/_/ /_/ /_/ ,___/_/\____/____/ '
echo ' /_/ ...is now updated!'
echo ''
echo ''
echo 'Just enjoy it!'
echo 'p.s. Follow me at https://github.com/chxuan.'
echo ''
printf "${normal}"
}
# 在mac更新vimplus
function update_vimplus_on_mac()
{
git pull origin master
copy_files
update_fonts_on_mac
update_vim_plugin
print_logo
}
# 在linux更新vimplus
function update_vimplus_on_linux()
{
git pull origin master
copy_files
update_fonts_on_linux
update_vim_plugin
print_logo
}
# 在android更新vimplus
function update_vimplus_on_android()
{
git pull origin master
copy_files
update_fonts_on_android
update_vim_plugin
print_logo
}
# 获取当前时间戳
function get_now_timestamp()
{
cur_sec_and_ns=`date '+%s-%N'`
echo ${cur_sec_and_ns%-*}
}
# main函数
function main()
{
begin=`get_now_timestamp`
type=$(uname)
echo "Platform type: "${type}
if [ ${type} == "Darwin" ]; then
update_vimplus_on_mac
elif [ ${type} == "Linux" ]; then
tp=$(uname -a)
if [[ $tp =~ "Android" ]]; then
echo "Android"
update_vimplus_on_android
else
update_vimplus_on_linux
fi
else
echo "Not support platform type: "${type}
fi
end=`get_now_timestamp`
second=`expr ${end} - ${begin}`
min=`expr ${second} / 60`
echo "It takes "${min}" minutes."
}
# 调用main函数
main