Skip to content

Commit a6de941

Browse files
committed
Issue #13: Auto update
1 parent 0097f06 commit a6de941

File tree

6 files changed

+213
-91
lines changed

6 files changed

+213
-91
lines changed

.editorconfig

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# This file is for unifying the coding style for different editors and IDEs
2+
# editorconfig.org
3+
4+
root = true
5+
6+
[*]
7+
charset = utf-8
8+
9+
indent_style = space
10+
indent_size = 4
11+
12+
end_of_line = lf
13+
trim_trailing_whitespace = true
14+
insert_final_newline = true

README.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ You can install it by using CLI just have next command executed
1717

1818
.. code-block:: bash
1919
20-
sh -c "$(curl -fsSL https://raw.githubusercontent.com/ets-labs/python-vimrc/master/setup.sh)"
20+
bash -c "$(curl -fsSL https://raw.githubusercontent.com/ets-labs/python-vimrc/master/init.sh)" [install|update|help]
2121
2222
During execution of init script do not worry about error messages. When it
2323
occurs just press enter and wait till all plugins are installed.

init.sh

+134
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
#!/usr/bin/env bash
2+
3+
# Use colors, but only if connected to a terminal, and that terminal
4+
# supports them.
5+
if which tput >/dev/null 2>&1; then
6+
ncolors=$(tput colors)
7+
fi
8+
if [ -t 1 ] && [ -n "$ncolors" ] && [ "$ncolors" -ge 8 ]; then
9+
RED="$(tput setaf 1)"
10+
GREEN="$(tput setaf 2)"
11+
YELLOW="$(tput setaf 3)"
12+
BLUE="$(tput setaf 4)"
13+
BOLD="$(tput bold)"
14+
NORMAL="$(tput sgr0)"
15+
else
16+
RED=""
17+
GREEN=""
18+
YELLOW=""
19+
BLUE=""
20+
BOLD=""
21+
NORMAL=""
22+
fi
23+
24+
ORG_NAME="ets-labs"
25+
REPO_NAME="python-vimrc"
26+
INIT_BASH_PATH="https://raw.githubusercontent.com/${ORG_NAME}/${REPO_NAME}/master/init.sh"
27+
VIMRC_URL="https://github.com/${ORG_NAME}/${REPO_NAME}.git"
28+
VUNDLE_URL="https://github.com/VundleVim/Vundle.vim.git"
29+
WOMBAT256MOD_URL="http://www.vim.org/scripts/download_script.php?src_id=13400"
30+
UPDATE_INTERVAL_DAYS=7
31+
32+
if [ ! -n "${VIM}" ]; then
33+
VIM=~/.vim
34+
fi
35+
36+
HELLO_TEXT=$(cat <<HEREDOC
37+
38+
iiii
39+
i::::i
40+
iiii
41+
42+
vvvvvvv vvvvvvviiiiiii mmmmmmm mmmmmmm rrrrr rrrrrrrrr cccccccccccccccc
43+
v:::::v v:::::v i:::::i mm:::::::m m:::::::mm r::::rrr:::::::::r cc:::::::::::::::c
44+
v:::::v v:::::v i::::i m::::::::::mm::::::::::mr:::::::::::::::::r c:::::::::::::::::c
45+
v:::::v v:::::v i::::i m::::::::::::::::::::::mrr::::::rrrrr::::::rc:::::::cccccc:::::c
46+
v:::::v v:::::v i::::i m:::::mmm::::::mmm:::::m r:::::r r:::::rc::::::c ccccccc
47+
v:::::v v:::::v i::::i m::::m m::::m m::::m r:::::r rrrrrrrc:::::c
48+
v:::::v:::::v i::::i m::::m m::::m m::::m r:::::r c:::::c
49+
v:::::::::v i::::i m::::m m::::m m::::m r:::::r c::::::c ccccccc
50+
v:::::::v i::::::im::::m m::::m m::::m r:::::r c:::::::cccccc:::::c
51+
v:::::v i::::::im::::m m::::m m::::m r:::::r c:::::::::::::::::c
52+
v:::v i::::::im::::m m::::m m::::m r:::::r cc:::::::::::::::c
53+
vvv iiiiiiiimmmmmm mmmmmm mmmmmm rrrrrrr cccccccccccccccc
54+
55+
HEREDOC
56+
)
57+
58+
is_git_exists() {
59+
hash git >/dev/null 2>&1
60+
}
61+
62+
install() {
63+
printf "${BLUE}%s${NORMAL}\n\n" "${HELLO_TEXT}"
64+
65+
is_git_exists || {
66+
printf "${RED}%s${NORMAL}\n" "Error: git is not installed."
67+
exit 1
68+
}
69+
70+
if [ -d "${VIM}" ]; then
71+
printf "${YELLOW}%s${NORMAL}\n" "You already have ${VIM} directory."
72+
printf "${YELLOW}%s${NORMAL}\n" "You have to remove ${VIM} if you want to re-install."
73+
exit 0
74+
fi
75+
76+
# Prevent the cloned repository from having insecure permissions. Failing to do
77+
# so causes compinit() calls to fail with "command not found: compdef" errors
78+
# for users with insecure umasks (e.g., "002", allowing group writability). Note
79+
# that this will be ignored under Cygwin by default, as Windows ACLs take
80+
# precedence over umasks except for filesystems mounted with option "noacl".
81+
umask g-w,o-w
82+
83+
printf "${GREEN}%s${NORMAL}\n" "Cloning vimrc from ${VIMRC_URL}"
84+
env git clone --depth=1 ${VIMRC_URL} ${VIM} || {
85+
printf "${RED}%s${NORMAL}\n" "Error: git clone of vimrc repo failed."
86+
exit 1
87+
}
88+
89+
printf "${BLUE}%s${NORMAL}\n" "Looking for an existing vim config..."
90+
if [ -f ~/.vimrc ] || [ -h ~/.vimrc ]; then
91+
printf "${YELLOW}%s${NORMAL}\n" "Found ~/.vimrc."
92+
printf "${BLUE}%s${NORMAL}\n" "You will see your old ~/.vimrc as ${VIM}/vimrc.bak"
93+
mv ~/.vimrc ${VIM}/vimrc.bak
94+
fi
95+
96+
printf "${BLUE}%s${NORMAL}\n" "Symlinking ${VIM}/vimrc with ~/.vimrc..."
97+
ln -fs ${VIM}/vimrc ~/.vimrc
98+
99+
if [ ! -d "$VIM/bundle/Vundle.vim" ]; then
100+
printf "${BLUE}%s${NORMAL}\n" "Installing Vundle..."
101+
env git clone --depth=1 ${VUNDLE_URL} "${VIM}/bundle/Vundle.vim"
102+
fi
103+
104+
if [ ! -f ${VIM}/colors/wombat256mod.vim ]; then
105+
if [ ! -d ${VIM}/colors/ ]; then
106+
mkdir -p ${VIM}/colors
107+
fi
108+
wget ${WOMBAT256MOD_URL} -O ${VIM}/colors/wombat256mod.vim
109+
fi
110+
111+
printf "${GREEN}%s${NORMAL}\n" "Vimrc has been configured ;)"
112+
printf "${YELLOW}%s${NORMAL}\n" "Do not worry about error messages. When it occurs just press enter and wait till all plugins are installed."
113+
printf "${BLUE}%s${NORMAL}\n" "Keep calm and use VIM!"
114+
115+
vim +PluginInstall
116+
}
117+
118+
help() {
119+
printf "${BLUE}%s${NORMAL}\n\n" "${HELLO_TEXT}"
120+
cat <<HEREDOC
121+
SYNOPSIS
122+
bash -c "\$(curl -fsSL ${INIT_BASH_PATH})" [install|help]
123+
124+
HEREDOC
125+
}
126+
127+
case "${0}" in
128+
"install")
129+
install
130+
;;
131+
"help")
132+
help
133+
;;
134+
esac

setup.sh

-90
This file was deleted.

update.sh

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#!/usr/bin/env bash
2+
3+
. init.sh
4+
5+
current_epoch() {
6+
echo $(( $(date +%s) / 60 / 60 / 24 ))
7+
}
8+
9+
last_update_vimrc() {
10+
echo "LAST_UPDATE=$(current_epoch)" > ${VIM}/.lastupdate
11+
}
12+
13+
upgrade_vimrc() {
14+
. upgrade.sh
15+
}
16+
17+
# Cancel upgrade if the current user doesn't have write permissions for the VIM directory.
18+
[[ -w "${VIM}" ]] || exit 0
19+
20+
# Cancel upgrade if git is unavailable on the system
21+
is_git_exists || exit 0
22+
23+
24+
if [ -f ${VIM}/.lastupdate ]
25+
then
26+
. ${VIM}/.lastupdate
27+
28+
if [[ -z "${LAST_UPDATE}" ]]; then
29+
last_update_vimrc && return 0;
30+
fi
31+
32+
EPOCH_DIFF=$(($(current_epoch) - ${LAST_UPDATE}))
33+
if [ ${EPOCH_DIFF} -gt ${UPDATE_INTERVAL_DAYS} ]
34+
then
35+
printf "${BLUE}%s${NORMAL}\n\n" "${HELLO_TEXT}"
36+
echo "${YELLOW}Would you like to check for updates? [Y/n]:${NORMAL}"
37+
read line
38+
if [[ "$line" == Y* ]] || [[ "$line" == y* ]] || [ -z "$line" ]; then
39+
upgrade_vimrc
40+
else
41+
last_update_vimrc
42+
fi
43+
fi
44+
else
45+
last_update_vimrc
46+
fi

upgrade.sh

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/usr/bin/env bash
2+
3+
. init.sh
4+
5+
wrapper() {
6+
printf "${BLUE}%s${NORMAL}\n\n" "${HELLO_TEXT}"
7+
8+
is_git_exists || {
9+
printf "${RED}%s${NORMAL}\n" "Error: git is not installed."
10+
exit 1
11+
}
12+
13+
git pull --rebase --stat origin master || {
14+
printf "${RED}%s${NORMAL}\n" "There are an error updating. Try again later."
15+
}
16+
}
17+
18+
wrapper

0 commit comments

Comments
 (0)