All in one solution for all the scripts of vim from vim.org

For quite sometime now, I was looking for some console based program which would help me get the scripts from vim.org. A simple solution would have been to do a wget for the scripts. But since there are so many scripts coming up daily and with a need to search based on script ID and name of the script, I thought better to write a script that can do all of those things. Now, what was required was that the script should be either able to download this or add to the GLVS script. Also note that, I had done something similar in the past here. There are some additions in the below script. You can download a copy of the script get_vim_scripts. Or you can copy the script from below:

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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
#!/bin/bash -
#===============================================================================
#
#          FILE:  get_scripts.sh
#
#         USAGE:  ./get_scripts.sh
#
#   DESCRIPTION:  Script to get the required vim script from the http
#                   server vim.org
#
#       OPTIONS:  ---
#  REQUIREMENTS:  ---
#          BUGS:  ---
#         NOTES:  ---
#        AUTHOR:  Amit Agarwal (AKA), amit.agarwal@amit-agarwal.co.in
#       COMPANY:  Individual
#       VERSION:  1.0
#       CREATED:  01/06/2010 10:06:27 PM IST
#      REVISION: Wed 24 Mar 2010 10:50:37 PM IST
#===============================================================================

#-------------------------------------------------------------------------------
#   You mostly would not need to change the below params also,
#   but just in case you do not like to see my name or do
#   not like the location for these files, then you can change the name of
#   files in the below variables.
#
#   As a side note, it is good idea to keep them in location where they are
#   not deleted automatically so that the same can be used over and over
#   again, without downloading them.
#-------------------------------------------------------------------------------

tmp_file="/tmp/vim_scripts.html"
script_id_file="/tmp/script_id"

##========Do not change below this line...======

#===  FUNCTION  ================================================================
#          NAME:  download_list
#   DESCRIPTION:  Download the list of vim scripts and put it in a file.
#    PARAMETERS:  NA
#       RETURNS:  NA
#===============================================================================
download_list()
{
downloaded=1
if [ ! -f $tmp_file ]
then
wget -O $tmp_file 'http://www.vim.org/scripts/script_search_results.php?&show_me=4000&result_ptr=0' -o /dev/null
else
echo "using the existing $tmp_file"
fi
}

#===  FUNCTION  ================================================================
#          NAME:  get_list
#   DESCRIPTION:  Get the list of scripts from the vim.sf.net
#    PARAMETERS:  None
#       RETURNS:  Nothing
#===============================================================================
search_list ()
{

read -p "Enter the text to search :: " text
pager_exist=$(which $PAGER 2>/dev/null)
if [ "$pager_exist" = "" ]
then
echo "No pager defined that can be used, displaying the first 10 entries"
cat $tmp_file | grep width| grep script_id= |sed 's/.*script_id=//'|tr -d "\""|tr ">" " "|sed 's/<.*//' | tr -d '\001'-'\011''\013''\014''\016'-'\037''\200'-'\377' |grep -i "$text"
else
if [ "x$1" = "x" ]
then
cat $tmp_file | grep width| grep script_id= |sed 's/.*script_id=//'|tr -d "\""|tr ">" " "|sed 's/<.*//' | tr -d '\001'-'\011''\013''\014''\016'-'\037''\200'-'\377' |grep -i "$text"|$PAGER
else
cat $tmp_file | grep width| grep script_id= |sed 's/.*script_id=//'|tr -d "\""|tr ">" " "|sed 's/<.*//' | tr -d '\001'-'\011''\013''\014''\016'-'\037''\200'-'\377' |grep -i "$text"|$PAGER
fi
fi
echo "--$1--"

}
get_all_list()
{
echo "Printing the list of the scripts with the script ID's"
pager_exist=$(which $PAGER 2>/dev/null)
if [ "$pager_exist" = "" ]
then
echo "No pager defined that can be used, displaying the first 10 entries"
cat $tmp_file | grep width| grep script_id= |sed 's/.*script_id=//'|tr -d "\""|tr ">" " "|sed 's/<.*//' | tr -d '\001'-'\011''\013''\014''\016'-'\037''\200'-'\377' |sort -n|head -n 10
else
if [ "x$1" = "x" ]
then
cat $tmp_file | grep width| grep script_id= |sed 's/.*script_id=//'|tr -d "\""|tr ">" " "|sed 's/<.*//' | tr -d '\001'-'\011''\013''\014''\016'-'\037''\200'-'\377' |sort -n|$PAGER
else
cat $tmp_file | grep width| grep script_id= |sed 's/.*script_id=//'|tr -d "\""|tr ">" " "|sed 's/<.*//' | tr -d '\001'-'\011''\013''\014''\016'-'\037''\200'-'\377' |$PAGER
fi
fi
echo "--$1--"

}

#===  FUNCTION  ================================================================
#          NAME:  get_details
#   DESCRIPTION:  Get the details of the Sript ID
#    PARAMETERS:  NA
#       RETURNS:  NA
#===============================================================================
get_details()
{
echo -n "Enter the script ID to get the details :"
read script_id
if [ ! -f $script_id_file$script_id ]
then
wget -o /dev/null -O $script_id_file$script_id 'http://www.vim.org/scripts/script.php?script_id='$script_id |html2text
fi
printf "%20s"
printf "%20s\n\n\n" "+"|tr ' ' '+'

h2t=`which html2text 2>/dev/null`
if [ $h2t = "" ]
then
cat $script_id_file$script_id|sed --silent '/description/,/\/table/ p'
else
cat $script_id_file$script_id|sed --silent '/description/,/\/table/ p'|html2text
fi
printf "%20s"
printf "%20s\n\n\n" "+"|tr ' ' '+'
}

#===  FUNCTION  ================================================================
#          NAME:  print_header
#   DESCRIPTION:  Print the header for the script
#    PARAMETERS:  NA
#       RETURNS:  NA
#===============================================================================
print_header()
{
printf "\n\n\n%80s\n" "="|tr ' ' '='
echo "        Welcome to VIM Scripts utility"
echo "        Script written by Amit Agarwal"
echo "        http://blog.amit-agarwal.co.in"
printf "%80s\n" "="|tr ' ' '='

cat << EOF
Menu
====
1. Get the list of all scripts
2. Get the description for the script
3. Download the script
4. Add the script to GetVIMLatestScript
5. Get selective list for scripts
6. Delete the existing list of all scripts
7. Get the list of all scripts in reverse order
8. Search the plugin list.
p. Change Pager
q. Quit the script
----------------------------------------------
EOF
}

#===  FUNCTION  ================================================================
#          NAME:  get_script
#   DESCRIPTION:  Download the vim script
#    PARAMETERS:  NA
#       RETURNS:  NA
#===============================================================================
get_script()
{
read -p "Enter the script ID to download :: " script_id
echo "Downloading the description"
if [ ! -f $script_id_file$script_id ]
then
wget -o /dev/null -O $script_id_file$script_id 'http://www.vim.org/scripts/script.php?script_id='$script_id
fi
src_id_tmp=$(cat $script_id_file$script_id|grep src_id|head -1|sed -e 's/.*href="//')
src_id=$(echo $src_id_tmp|sed  -e 's/".*//')
filename=$(echo $src_id_tmp|sed  's/.*">//' |sed 's#<.*##')
echo "Downloading the file as $filename"
curl http://www.vim.org/scripts/$src_id 2>/dev/null > $filename
}

#===  FUNCTION  ================================================================
#          NAME:  add_script2GVLS
#   DESCRIPTION:  Add the script id to Get Latest VIM Scripts
#    PARAMETERS:  NA
#       RETURNS:  NA
#===============================================================================
add_script2GVLS()
{
read -p "Enter the Script ID to add : " script_id
script_name=$(cat $tmp_file | grep width| grep script_id= |sed 's/.*script_id=//'|tr -d "\""|tr ">" " "|sed 's/<.*//' |sort -n|grep "^$script_id "|sed 's/\([0-9]*\)\(.*\)/\2/')
echo "$script_id 1 $script_name"
cp ~/.vim/GetLatest/GetLatestVimScripts.dat ~/.vim/GetLatest/GetLatestVimScripts.backup
echo "$script_id 1 :AutoInstall: $script_name" >> ~/.vim/GetLatest/GetLatestVimScripts.dat
}

#===  FUNCTION  ================================================================
#          NAME:  get_list
#   DESCRIPTION:  Get the list of scripts for selective items
#    PARAMETERS:  NA
#       RETURNS:  NA
#===============================================================================
get_list()
{
echo "Getting the web page for the list of scripts..."
echo "Please be patient"

read -p "Enter the script ID to start from :" start_id
read -p "Enter the number of entries to display :" number_display
echo "Printing the list of the scripts with the script ID's from $start_id"

printf "\n\n%75s\n"|tr ' ' '='

cat $tmp_file | grep width| grep script_id= |sed 's/.*script_id=//'|tr -d "\""|tr ">" " "|sed 's/<.*//' |sort -n|sed -n '/^'$start_id' /,$ p'|head -n $number_display
printf "%75s\n\n\n\n"|tr ' ' '='
}

#-------------------------------------------------------------------------------
#   This is where we start the actual script in a infinite
#   loop. You can exit the loop with q.
#-------------------------------------------------------------------------------
echo "Getting the list of scripts ...."
echo "Hold on a few seconds, while I do some dirty work :)"
download_list
while true
do

print_header

read -p "Please enter your choice : " read_choice

case $read_choice in
'1')
get_all_list
;;
'2')
get_details
;;
'3')
get_script
;;
'4')
add_script2GVLS
;;
'5')
get_list
;;
'6')
rm -f $tmp_file
;;
'7')
get_all_list 1
;;
'8')
search_list
;;
'p')
echo "Current pager is $PAGER"
read -p "Enter the name of the pager to use :: " pager
export PAGER=$pager
;;
'q')
exit 0
;;
*)
echo "Not a valid input"
;;
esac
done

 

6 thoughts on “All in one solution for all the scripts of vim from vim.org”

    1. Thanks for the link. The script is working in bash-4.7.1(1) version at least. If you give while true do in one line, it will not work definitely, but if not in single line, it works 🙂
      I will try and install the MarcWeber script and addon, but my script is completely in bash and does not add anything to vim. It is capable of adding the scripts to GLVS dat file and searchable.

      1. You’ve been right. Sorry. I’ve written on the mailinglist about more reasons. I’d like to work towards having one tool which is found by all Vim users and which all Vim users use. A simple script like yours is very easy to miss and get lots and therefore someone else will rewrite it .. Then someone else may find two scripts and wonder which one to use .. I’d like you to find out whether it would be an option to you helping to maintain vim-addon-manager merging your ideas into that project. Then you’ll get more users as well instantly. Keep this blog – but consider hosting your code on a dedicated code hosting service such as github. By the way its funny to see a picture which should be my face – but which of course is not 🙂 If you have any questions about VAM – the homepage or the like ping back so that we can improve the overall situtation.

        1. I will host the code somewhere and update the post. For the vim-addon-manager part, I will reply in the mailinglist.
          About the picture, it is not yours because Gravtar is not finding your pic for the Email ID you registered and hence puts the default pic, which is mine 🙁