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

2011-03-09 1787 words 9 mins read

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:

  <td>
    <div class="text codecolorer">
      #!/bin/bash -<br /> #===============================================================================<br /> #<br /> #          FILE:  get_scripts.sh<br /> #<br /> #         USAGE:  ./get_scripts.sh<br /> #<br /> #   DESCRIPTION:  Script to get the required vim script from the http<br /> #                   server vim.org<br /> #<br /> #       OPTIONS:  ---<br /> #  REQUIREMENTS:  ---<br /> #          BUGS:  ---<br /> #         NOTES:  ---<br /> #        AUTHOR:  Amit Agarwal (AKA), amit.agarwal@amit-agarwal.co.in<br /> #       COMPANY:  Individual<br /> #       VERSION:  1.0<br /> #       CREATED:  01/06/2010 10:06:27 PM IST<br /> #      REVISION: Wed 24 Mar 2010 10:50:37 PM IST<br /> #===============================================================================<br /> <br /> #-------------------------------------------------------------------------------<br /> #   You mostly would not need to change the below params also,<br /> #   but just in case you do not like to see my name or do<br /> #   not like the location for these files, then you can change the name of<br /> #   files in the below variables.<br /> #<br /> #   As a side note, it is good idea to keep them in location where they are<br /> #   not deleted automatically so that the same can be used over and over<br /> #   again, without downloading them.<br /> #-------------------------------------------------------------------------------<br /> <br /> tmp_file="/tmp/vim_scripts.html"<br /> script_id_file="/tmp/script_id"<br /> <br /> ##========Do not change below this line...======<br /> <br /> #===  FUNCTION  ================================================================<br /> #          NAME:  download_list<br /> #   DESCRIPTION:  Download the list of vim scripts and put it in a file.<br /> #    PARAMETERS:  NA<br /> #       RETURNS:  NA<br /> #===============================================================================<br /> download_list()<br /> {<br /> downloaded=1<br /> if [ ! -f $tmp_file ]<br /> then<br /> wget -O $tmp_file 'http://www.vim.org/scripts/script_search_results.php?&show_me=4000&result_ptr=0' -o /dev/null<br /> else<br /> echo "using the existing $tmp_file"<br /> fi<br /> }<br /> <br /> #===  FUNCTION  ================================================================<br /> #          NAME:  get_list<br /> #   DESCRIPTION:  Get the list of scripts from the vim.sf.net<br /> #    PARAMETERS:  None<br /> #       RETURNS:  Nothing<br /> #===============================================================================<br /> search_list ()<br /> {<br /> <br /> read -p "Enter the text to search :: " text<br /> pager_exist=$(which $PAGER 2>/dev/null)<br /> if [ "$pager_exist" = "" ]<br /> then<br /> echo "No pager defined that can be used, displaying the first 10 entries"<br /> 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"<br /> else<br /> if [ "x$1" = "x" ]<br /> then<br /> 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<br /> else<br /> 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<br /> fi<br /> fi<br /> echo "--$1--"<br /> <br /> }<br /> get_all_list()<br /> {<br /> echo "Printing the list of the scripts with the script ID's"<br /> pager_exist=$(which $PAGER 2>/dev/null)<br /> if [ "$pager_exist" = "" ]<br /> then<br /> echo "No pager defined that can be used, displaying the first 10 entries"<br /> 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<br /> else<br /> if [ "x$1" = "x" ]<br /> then<br /> 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<br /> else<br /> 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<br /> fi<br /> fi<br /> echo "--$1--"<br /> <br /> }<br /> <br /> #===  FUNCTION  ================================================================<br /> #          NAME:  get_details<br /> #   DESCRIPTION:  Get the details of the Sript ID<br /> #    PARAMETERS:  NA<br /> #       RETURNS:  NA<br /> #===============================================================================<br /> get_details()<br /> {<br /> echo -n "Enter the script ID to get the details :"<br /> read script_id<br /> if [ ! -f $script_id_file$script_id ]<br /> then<br /> wget -o /dev/null -O $script_id_file$script_id 'http://www.vim.org/scripts/script.php?script_id='$script_id |html2text<br /> fi<br /> printf "%20s"<br /> printf "%20s\n\n\n" "+"|tr ' ' '+'<br /> <br /> h2t=`which html2text 2>/dev/null`<br /> if [ $h2t = "" ]<br /> then<br /> cat $script_id_file$script_id|sed --silent '/description/,/\/table/ p'<br /> else<br /> cat $script_id_file$script_id|sed --silent '/description/,/\/table/ p'|html2text<br /> fi<br /> printf "%20s"<br /> printf "%20s\n\n\n" "+"|tr ' ' '+'<br /> }<br /> <br /> #===  FUNCTION  ================================================================<br /> #          NAME:  print_header<br /> #   DESCRIPTION:  Print the header for the script<br /> #    PARAMETERS:  NA<br /> #       RETURNS:  NA<br /> #===============================================================================<br /> print_header()<br /> {<br /> printf "\n\n\n%80s\n" "="|tr ' ' '='<br /> echo "        Welcome to VIM Scripts utility"<br /> echo "        Script written by Amit Agarwal"<br /> echo "        http://blog.amit-agarwal.co.in"<br /> printf "%80s\n" "="|tr ' ' '='<br /> <br /> cat << EOF<br /> Menu<br /> ====<br /> 1. Get the list of all scripts<br /> 2. Get the description for the script<br /> 3. Download the script<br /> 4. Add the script to GetVIMLatestScript<br /> 5. Get selective list for scripts<br /> 6. Delete the existing list of all scripts<br /> 7. Get the list of all scripts in reverse order<br /> 8. Search the plugin list.<br /> p. Change Pager<br /> q. Quit the script<br /> ----------------------------------------------<br /> EOF<br /> }<br /> <br /> #===  FUNCTION  ================================================================<br /> #          NAME:  get_script<br /> #   DESCRIPTION:  Download the vim script<br /> #    PARAMETERS:  NA<br /> #       RETURNS:  NA<br /> #===============================================================================<br /> get_script()<br /> {<br /> read -p "Enter the script ID to download :: " script_id<br /> echo "Downloading the description"<br /> if [ ! -f $script_id_file$script_id ]<br /> then<br /> wget -o /dev/null -O $script_id_file$script_id 'http://www.vim.org/scripts/script.php?script_id='$script_id<br /> fi<br /> src_id_tmp=$(cat $script_id_file$script_id|grep src_id|head -1|sed -e 's/.*href="//')<br /> src_id=$(echo $src_id_tmp|sed  -e 's/".*//')<br /> filename=$(echo $src_id_tmp|sed  's/.*">//' |sed 's#<.*##')<br /> echo "Downloading the file as $filename"<br /> curl http://www.vim.org/scripts/$src_id 2>/dev/null > $filename<br /> }<br /> <br /> #===  FUNCTION  ================================================================<br /> #          NAME:  add_script2GVLS<br /> #   DESCRIPTION:  Add the script id to Get Latest VIM Scripts<br /> #    PARAMETERS:  NA<br /> #       RETURNS:  NA<br /> #===============================================================================<br /> add_script2GVLS()<br /> {<br /> read -p "Enter the Script ID to add : " script_id<br /> 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/')<br /> echo "$script_id 1 $script_name"<br /> cp ~/.vim/GetLatest/GetLatestVimScripts.dat ~/.vim/GetLatest/GetLatestVimScripts.backup<br /> echo "$script_id 1 :AutoInstall: $script_name" >> ~/.vim/GetLatest/GetLatestVimScripts.dat<br /> }<br /> <br /> #===  FUNCTION  ================================================================<br /> #          NAME:  get_list<br /> #   DESCRIPTION:  Get the list of scripts for selective items<br /> #    PARAMETERS:  NA<br /> #       RETURNS:  NA<br /> #===============================================================================<br /> get_list()<br /> {<br /> echo "Getting the web page for the list of scripts..."<br /> echo "Please be patient"<br /> <br /> read -p "Enter the script ID to start from :" start_id<br /> read -p "Enter the number of entries to display :" number_display<br /> echo "Printing the list of the scripts with the script ID's from $start_id"<br /> <br /> printf "\n\n%75s\n"|tr ' ' '='<br /> <br /> 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<br /> printf "%75s\n\n\n\n"|tr ' ' '='<br /> }<br /> <br /> #-------------------------------------------------------------------------------<br /> #   This is where we start the actual script in a infinite<br /> #   loop. You can exit the loop with q.<br /> #-------------------------------------------------------------------------------<br /> echo "Getting the list of scripts ...."<br /> echo "Hold on a few seconds, while I do some dirty work :)"<br /> download_list<br /> while true<br /> do<br /> <br /> print_header<br /> <br /> read -p "Please enter your choice : " read_choice<br /> <br /> case $read_choice in<br /> '1')<br /> get_all_list<br /> ;;<br /> '2')<br /> get_details<br /> ;;<br /> '3')<br /> get_script<br /> ;;<br /> '4')<br /> add_script2GVLS<br /> ;;<br /> '5')<br /> get_list<br /> ;;<br /> '6')<br /> rm -f $tmp_file<br /> ;;<br /> '7')<br /> get_all_list 1<br /> ;;<br /> '8')<br /> search_list<br /> ;;<br /> 'p')<br /> echo "Current pager is $PAGER"<br /> read -p "Enter the name of the pager to use :: " pager<br /> export PAGER=$pager<br /> ;;<br /> 'q')<br /> exit 0<br /> ;;<br /> *)<br /> echo "Not a valid input"<br /> ;;<br /> esac<br /> done
    </div>
  </td>
</tr>
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

 


author

Authored By Amit Agarwal

Amit Agarwal, Linux and Photography are my hobbies.Creative Commons Attribution 4.0 International License.

We notice you're using an adblocker. If you like our webite please keep us running by whitelisting this site in your ad blocker. We’re serving quality, related ads only. Thank you!

I've whitelisted your website.

Not now
This website uses cookies to ensure you get the best experience on our website. Learn more Got it