-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvim-pack-export
executable file
·114 lines (105 loc) · 2.59 KB
/
vim-pack-export
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
#! /usr/bin/env bash
repo_dir=$HOME/.vim/pack/git-plugins
silent=false
supports_long_opts=false
getopt --test > /dev/null
if (( $? == 4 )); then
supports_long_opts=true
fi
####
# This handles the optional arguments
###
ofile_specified=false
SHORT=hsd:
LONG=help,silent,git-dir:
if [[ $supports_long_opts == true ]]; then
PARSED=$(getopt --options $SHORT --longoptions $LONG --name "$0" -- "$@")
else
PARSED=$(getopt --options $SHORT --name "$0" -- "$@")
fi
if (( $? != 0 )); then
echo 'Failed to parse arguments'
exit 2
fi
eval set -- "$PARSED"
while true; do
case "$1" in
-h|--help)
usage=true
break
;;
-d|--git-dir)
repo_dir=$2
shift 2
;;
-s|--silent)
silent=true
shift
;;
--)
shift
break
;;
*)
break
;;
esac
done
if [[ $usage == true ]]; then
echo 'usage: vim-pack export [-s|--silent] [-d <dir>| --git-dir=<dir>] [<file>]'
echo 'usage: vim-pack list [-s|--silent] [-d <dir>| --git-dir=<dir>] [<file>]'
echo
echo
echo ' If <file> is provided then the list of packages will be exported to a file'
echo ' following the INI file format. If the -s or --silent option arguments are'
echo ' given then an output file is mandatory. This is useful for transferring '
echo ' configurations across machines and for listing all installed packages'
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
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
exit 0
fi
if [[ ! -z "$1" ]]; then
outfile=$1
ofile_specified=true
fi
if [[ "$silent" == true ]] && [[ "$ofile_specified" == false ]]; then
echo "Cannot export silent without a output file specified"
echo "Provide an output file"
exit 1
fi
repo_list=''
for i in {opt,start}; do
repos_folders=$(ls "$repo_dir/$i/")
for j in $repos_folders; do
url=$(git -C "$repo_dir/$i/$j" remote get-url origin)
if [[ "$ofile_specified" == true ]]; then
repo_list+="[$j]\n"
repo_list+=" dir = $i/$j\n"
repo_list+=" url = $url\n"
fi
if [[ "$silent" == false ]]; then
echo "[$j]"
echo " dir = $i/$j"
echo " url = $url"
fi
done
done
if [[ "$ofile_specified" == true ]]; then
echo -e "$repo_list" > "$outfile"
fi
exit 0