-
Notifications
You must be signed in to change notification settings - Fork 4
/
install_plugin.sh
152 lines (131 loc) · 3.03 KB
/
install_plugin.sh
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
146
147
148
149
150
151
152
#!/bin/bash
# install.sh -- created 2010-09-15, Tom Link
# @Last Change: 2010-09-26.
# @Revision: 0.140
if [ -e $HOME/vimfiles ]; then
VIMFILES=$HOME/vimfiles
else
VIMFILES=$HOME/.vim
fi
VIM=vim
PRE=
CP=cp
MKDIR=mkdir
HELPTAGS=false
VERBOSE=false
if [ -e $VIMFILES/install_plugin.rc ]; then
. $VIMFILES/install_plugin.rc
fi
function usage {
echo "`basename $0` [OPTIONS] DIR1 DIR2 ..."
echo "If no directories are supplied, use the directories in \$VIMPLUGINS"
echo " "
echo "Options:"
echo " -d|--dir DIR ... Destination directory (default: $VIMFILES)"
echo " -n|--dry ... Show which files would be copied"
echo " -t|--helptags ... Create helptags"
echo " -u|--update ... Copy only newer files"
echo " --vim CMD ... VIM command (default: ${VIM})"
echo " -v|--verbose ... Show messages"
echo " -h|--help ... Show help"
echo " "
echo "Configuration file: $VIMFILES/install_plugin.rc"
exit 1
}
function findfiles {
find $1 -type f \
-not -wholename "*/.*" \
-not -wholename "*/_*" \
-not -name "Makefile" \
-not -wholename "*/doc/tags" \
-not -name README \
-print
}
function log {
if [ "$VERBOSE" == true ]; then
echo $@
fi
}
while [ -n $1 ]; do
case $1 in
-d|--dir)
VIMFILES=$2
shift 2
;;
-n|--dry)
PRE=echo
shift
;;
-t|--helptags)
HELPTAGS=true
shift
;;
-u|--update)
CP="$CP -u"
shift
;;
--vim)
VIM=$2
shift 2
;;
-v|--verbose)
CP="$CP -v"
MKDIR="$MKDIR -v"
VERBOSE=true
shift
;;
-h|--help)
usage
;;
*)
break
;;
esac
done
if [ ! -d "$VIMFILES" ]; then
echo "Error: Destination directory does not exist: $VIMFILES"
usage
fi
if [ -z $1 ]; then
if [ -z $VIMPLUGINS ]; then
echo "No directory is given and \$VIMPLUGINS is not set."
read -p "Copy files from '$PWD' to '$VIMFILES'? (y/N) " yesno
if [ "$yesno" != 'y' ]; then
echo "Cancel!"
exit 5
fi
fi
if [ -n $VIMPLUGINS ]; then
DIRS=`find $VIMPLUGINS -maxdepth 1 -type d -not -name ".*" -not -name "_*"`
else
echo "Error: \$VIMPLUGINS is undefined and no directories are given"
usage
fi
else
DIRS=$@
fi
for DIR in $DIRS; do
if [ -d $DIR ]; then
log Plugin: $DIR
cd $DIR
FILES=`findfiles .`
cd - > /dev/null
for FILE in $FILES; do
DDIR=`dirname ${VIMFILES}/$FILE`
if [ ! -e $DDIR ]; then
$PRE $MKDIR -p $DDIR
fi
$PRE $CP $DIR/$FILE ${VIMFILES}/$FILE
done
fi
done
if [ "$HELPTAGS" == true ]; then
if [ -d $VIMFILES/doc ]; then
cd $VIMFILES
log Create helptags ...
$VIM -u NONE -U NONE -c "helptags doc|q"
cd - > /dev/null
fi
fi
log Done!
# vi: ft=sh:tw=72:ts=4