-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvim-pack-update
executable file
·136 lines (126 loc) · 2.99 KB
/
vim-pack-update
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
#! /usr/bin/env bash
###
# Test some variables for setting up options
###
supports_long_opts=false
getopt --test > /dev/null
if (( $? == 4 )); then
supports_long_opts=true
fi
# Pull in code from parallel interface
my_dir="$(dirname "$(readlink "$0")")"
source "$my_dir/vim-pack-parallel"
###
# Prints the Usage message and exist return the first arg as return code
###
usage() {
echo 'usage: vim-pack update [-s|--silent] [-d <dir>| --git-dir=<dir>]'
echo
echo 'options:'
echo 'general options:'
echo ' -d <dir> | --git-dir=<dir>'
echo ' specify the name for the package directory by default it is'
echo ' $HOME/.vim/pack/git-plugins'
echo
echo ' -h| --help'
echo ' displays a really helpful message about how to use the program'
echo
echo ' -s| --silent'
echo ' to hide output that normally goes to stdout'
echo
echo ' -v| --verbose'
echo ' Prints out verbose output.'
echo
parallel_usage_options
echo
echo 'note:'
echo ' long options are only available with systems that have an enhanced version'
echo ' of getopt.'
if [[ $supports_long_opts == true ]]; then
echo ' this system does support long options'
else
echo ' this system does not support long options'
fi
parallel_usage_notes
echo
exit "$1"
}
# Repository Directory default location
repo_dir="$HOME/.vim/pack/git-plugins"
# silent is disabled by default
silent=false
# verbose is disabled by default
verbose=false
####
# This handles the optional arguments
###
SHORT="d:hsv$parallel_short_opts"
LONG="git-dir:,help,silent,verbose,$parallel_long_opts"
if [[ $supports_long_opts == true ]]; then
if ! PARSED=$(getopt --options $SHORT --longoptions $LONG --name "$0" -- "$@"); then
echo 'Failed to parse arguments'
usage 1
fi
else
if ! PARSED=$(getopt --options $SHORT --name "$0" -- "$@"); then
echo 'Failed to parse arguments'
usage 1
fi
fi
eval set -- "$PARSED"
while true; do
parallel_parse_opt "$@"
ret=$?
if (( ret != 0 )); then
shift $ret
continue
fi
case "$1" in
-h|--help)
usage 0
;;
-d|--git-dir)
repo_dir=$2
shift 2
;;
-s|--silent)
silent=true
shift
;;
-v|--verbose)
verbose=true
shift
;;
--)
shift
break
;;
esac
done
update_count=$(( 0 ))
update_list=""
if [[ "$silent" == true ]]; then
cmd='git -C "{}" fetch > /dev/null'
elif [[ "$verbose" == true ]]; then
cmd='out=$(git -C "{}" fetch); echo -e "git -C "{}" fetch\nChecked {}$out"'
else
cmd='out=$(git -C "{}" fetch); echo -e "Checked {}$out"'
fi
parallel_run "$cmd" $repo_dir/{opt,start}/*
# Don't know how to parallelize this but it takes very little time anyways so...
for i in {opt,start}; do
for j in $repo_dir/$i/*; do
_ahead=$(git -C "$j" rev-list "HEAD..@{u}" | wc -l)
if (( _ahead > 0 )); then
update_count=$(( update_count + 1 ))
update_list="$update_list ${j#"$repo_dir/$i/"}"
fi
done
done
if (( update_count > 0 )); then
echo 'Updates available for:'
echo " $update_list"
else
echo 'No updates available'
fi
exit 0