-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvim-pack-import
More file actions
executable file
·145 lines (134 loc) · 3.52 KB
/
vim-pack-import
File metadata and controls
executable file
·145 lines (134 loc) · 3.52 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
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
#! /usr/bin/env bash
my_dir="$(dirname "$(readlink "$0")")"
source "$my_dir/vim-pack-parallel"
source "$my_dir/bash_ini_parser/read_ini.sh"
supports_long_opts=false
getopt --test > /dev/null
if (( $? == 4 )); then
supports_long_opts=true
fi
usage() {
echo 'vim-pack import [-s|--silent] [-d <dir>| --git-dir=<dir>] <file>'
echo
echo '<file> is the name of the required INI format file. This can be generated using vim-pack export this is useful for'
echo 'transferring configurations between machines.'
echo
echo 'options:'
echo ' -s| --silent'
echo ' to hide output that normally goes to stdout'
echo
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
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"
}
repo_dir=$HOME/.vim/pack/git-plugins
silent=false
supports_long_opts=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
import_file=$1
if ! [[ -f "$import_file" ]]; then
echo "Import file does not exist. [ $import_file ]"
exit 1
fi
read_ini "$import_file"
if [[ $use_more == true ]] || [[ $use_gnu == true ]]; then
if [[ $silent == true ]]; then
cmd='source "'$my_dir'/bash_ini_parser/read_ini.sh"
read_ini "'$import_file'"
repo_target=${INI__{}__url}
dest_name=${INI__{}__dir}
git clone "$repo_target" "'$repo_dir'/$dest_name" > /dev/null'
elif [[ $verbose == true ]]; then
cmd='source "'$my_dir'/bash_ini_parser/read_ini.sh"
read_ini "'$import_file'"
repo_target=${INI__{}__url}
dest_name=${INI__{}__dir}
out=$(git clone "$repo_target" "'$repo_dir'/$dest_name")
echo -e "git clone $repo_target '$repo_dir'/$dest_name\n$out"'
else
cmd='source "'$my_dir'/bash_ini_parser/read_ini.sh"
read_ini "'$import_file'"
repo_target=${INI__{}__url}
dest_name=${INI__{}__dir}
echo git clone "$repo_target" "'$repo_dir'/$dest_name"
git clone "$repo_target" "'$repo_dir'/$dest_name" > /dev/null'
fi
parallel_run "$cmd" ${INI__ALL_SECTIONS}
else
for sec in ${INI__ALL_SECTIONS}; do
v="INI__${sec}__url"
repo_target=${!v}
v="INI__${sec}__dir"
dest_name=${!v}
if [[ $silent == true ]]; then
git clone "$repo_target" "$repo_dir/$dest_name" > /dev/null
elif [[ $verbose == true ]]; then
echo -e "git clone $repo_target $repo_dir/$dest_name"
git clone "$repo_target" "$repo_dir/$dest_name"
else
echo "git clone $repo_target $repo_dir/$dest_name"
git clone "$repo_target" "$repo_dir/$dest_name" > /dev/null
fi
done
fi
echo "Import done"
exit 0