|
| 1 | +" --------------------------------------------------------------------------- |
| 2 | +" Search the database from vim-script.org for a matching plugin. If no |
| 3 | +" argument is given, list all plugins. This function is used by the :Plugins |
| 4 | +" and :PluginSearch commands. |
| 5 | +" |
| 6 | +" ... -- a plugin name to search for |
| 7 | +" --------------------------------------------------------------------------- |
| 8 | +func! vundle#search#new(string) |
| 9 | + let info = ['"Keymap: i - Install plugin; c - Cleanup; s - Search; R - Reload list'] |
| 10 | + let url = s:search_url.'+'.a:string |
| 11 | + let query_result = s:search(url) |
| 12 | + " check error first |
| 13 | + if 0 == query_result[0] |
| 14 | + let false = 0 |
| 15 | + let true = 0 |
| 16 | + let null = 0 |
| 17 | + let res = substitute(query_result[1], "\n", "", 'g') |
| 18 | + let items = eval(res).items |
| 19 | + " echo items |
| 20 | + call vundle#scripts#view('search', info, vundle#search#bundle_names(items)) |
| 21 | + echo len(items).' plugins found' |
| 22 | + else |
| 23 | + call vundle#scripts#view('search', info, ['"An error running query']) |
| 24 | + endif |
| 25 | + redraw |
| 26 | +endf |
| 27 | + |
| 28 | +" --------------------------------------------------------------------------- |
| 29 | +" Create a list of 'Plugin ...' lines from a list of bundle names. |
| 30 | +" |
| 31 | +" names -- a list of names (strings) of plugins |
| 32 | +" return -- a list of 'Plugin ...' lines suitable to be written to a buffer |
| 33 | +" --------------------------------------------------------------------------- |
| 34 | +func! vundle#search#bundle_names(items) |
| 35 | + let r = [] |
| 36 | + for item in a:items |
| 37 | + call add(r, printf("Plugin '%s' \" %s", item.full_name, item.description)) |
| 38 | + endfo |
| 39 | + return r |
| 40 | +endf |
| 41 | + |
| 42 | +" --------------------------------------------------------------------------- |
| 43 | +" |
| 44 | +" to -- the filename (string) to save the database to |
| 45 | +" url -- the request url |
| 46 | +" return -- 0 on success, 1 if an error occurred |
| 47 | +" --------------------------------------------------------------------------- |
| 48 | + |
| 49 | +func! s:search(url) |
| 50 | + let url = vundle#installer#shellesc(a:url) |
| 51 | + |
| 52 | + if executable("curl") |
| 53 | + let cmd = 'curl --fail -s '.l:url |
| 54 | + elseif executable("wget") |
| 55 | + let cmd = 'wget -q -O - '.l:url |
| 56 | + else |
| 57 | + echoerr 'Error curl or wget is not available!' |
| 58 | + return [1] |
| 59 | + endif |
| 60 | + |
| 61 | + let response = system(cmd) |
| 62 | + |
| 63 | + if (0 != v:shell_error) |
| 64 | + echoerr 'Error fetching scripts!' |
| 65 | + endif |
| 66 | + return [v:shell_error, response] |
| 67 | +endf |
| 68 | + |
| 69 | +let s:search_url = 'https://api.github.com/search/repositories?q=language:VimL+user:vim-scripts' |
| 70 | + |
| 71 | +" vim: set expandtab sts=2 ts=2 sw=2 tw=78 norl: |
0 commit comments