-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathvim-plugins
More file actions
executable file
·113 lines (104 loc) · 3.24 KB
/
vim-plugins
File metadata and controls
executable file
·113 lines (104 loc) · 3.24 KB
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
#!/bin/sh
COLOR_RED="\033[0;31m"
COLOR_GREEN="\033[0;32m"
COLOR_BLUE="\033[0;34m"
COLOR_YELLOW="\033[0;33m"
COLOR_GRAY="\033[0;38;5;240m"
BOLD="\033[1m"
RESET="\033[0m"
update_plugin() {
dir="$(dirname "$1")"
plugin="$(basename "$1")"
cd "$1" || exit 1
git_output="$(LANG=en_US.UTF-8 git pull --progress 2>&1)"
result=$?
if [ "$git_output" = "Already up to date." ]; then
printf "$dir/${COLOR_BLUE}${BOLD}${plugin}${RESET} "
printf "$(git rev-parse --short HEAD) "
printf "${COLOR_GREEN}${git_output}${RESET}\n"
else
printf "$dir/${COLOR_BLUE}${BOLD}${plugin}${RESET} "
printf "$(git rev-parse --short HEAD) "
if [ $result = 0 ]; then
printf "${COLOR_YELLOW}${BOLD}Updated:${RESET}\n"
else
printf "${COLOR_RED}${BOLD}Update failed:${RESET}\n"
fi
printf "%s\n" "${git_output}"
fi
}
update_plugins() {
mkdir -p "$HOME/log"
logfile="$HOME/log/update-vim-plugins.log"
printf "\n###################\n" >> "$logfile"
date "+%Y-%m-%d %H:%M:%S" >> "$logfile"
for p in "$HOME"/.vim/pack/plugins/start/*; do
# using echo "$(...)" to print all function output at once
echo "$(update_plugin "$p")" &
done | tee -a "$logfile"
wait
for p in "$HOME"/.vim/pack/plugins/vim-only/*; do
echo "$(update_plugin "$p")" &
done | tee -a "$logfile"
wait
for p in "$HOME"/.vim/pack/plugins/opt/*; do
echo "$(update_plugin "$p")" &
done | tee -a "$logfile"
wait
}
case $1 in
''|-u|--update|update) update_plugins; exit;;
-i|--install|install) ;;
esac
clone_repo() {
sleep 0.1
cd "$1" && git clone $3 "$2" > /dev/null 2>&1
printf '.'
}
install_plugins() {
input_file="$1"
section="$2"
lines="$(sed -n "/^\[$section\]/,/^\[/p" "$input_file" | grep '^[^#[]' | sed 's/\s*#.*$//')"
while read -r plugin
do
[ $plugin ] || continue
printf " $plugin "
# if $plugin contains a comma, save part after first comma as $params
case "$plugin" in
*,*) params="--${plugin#*,}" ;;
*) params= ;;
esac
plugin=${plugin%%,*} # keep part before first comma
folder=${plugin##*/}
folder=${folder%.git}
dest_path="$HOME/.vim/pack/plugins/$section/$folder"
[ -d "$dest_path" ] \
&& printf "${COLOR_GRAY}Folder $folder already exists.${RESET}\n" \
&& continue
installation_count=$((installation_count+1))
printf "${COLOR_GREEN}Installing '$folder'...${RESET}\n"
case "$plugin" in
http*) url="$plugin" ;;
~*) url=https://git.sr.ht/"$plugin" ;;
*) url=https://github.com/"$plugin".git ;;
esac
clone_repo "$dir" "$url" "$params" &
done << EOF
$lines
EOF
}
installation_count=0
for types in start vim-only opt; do
dir="$HOME/.vim/pack/plugins/$types/"
printf "\n${BOLD}$dir${RESET}\n"
mkdir -p "$dir"
cd "$dir" || exit 1
install_plugins "$HOME/.vim/plugins" $types
case "$MACHINE" in
work*) install_plugins "$HOME/.vim/plugins-work" $types ;;
*) install_plugins "$HOME/.vim/plugins-home" $types ;;
esac
done
printf "\nDownloading $installation_count plugins.\n"
wait
printf "\nDone.\n"