Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PluginSearch github.com/vim-scripts/ through github api #660

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion autoload/vundle.vim
Expand Up @@ -12,7 +12,7 @@ com! -nargs=* -bang -complete=custom,vundle#scripts#complete PluginInstall
\ call vundle#installer#new('!' == '<bang>', <f-args>)

com! -nargs=? -bang -complete=custom,vundle#scripts#complete PluginSearch
\ call vundle#scripts#all('!' == '<bang>', <q-args>)
\ call vundle#search#new(<q-args>)

com! -nargs=0 -bang PluginList
\ call vundle#installer#list('!' == '<bang>')
Expand Down
71 changes: 71 additions & 0 deletions autoload/vundle/search.vim
@@ -0,0 +1,71 @@
" ---------------------------------------------------------------------------
" Search the database from vim-script.org for a matching plugin. If no
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose the comment needs updating now that we have embraced the github. the one true github. all hail our new overlords 👽

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@andxyz 😆 👍

Copy link

@ksHKK ksHKK Jul 13, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • [x]

" argument is given, list all plugins. This function is used by the :Plugins
" and :PluginSearch commands.
"
" ... -- a plugin name to search for
" ---------------------------------------------------------------------------
func! vundle#search#new(string)
let info = ['"Keymap: i - Install plugin; c - Cleanup; s - Search; R - Reload list']
let url = s:search_url.'+'.a:string
let query_result = s:search(url)
" check error first
if 0 == query_result[0]
let false = 0
let true = 0
let null = 0
let res = substitute(query_result[1], "\n", "", 'g')
let items = eval(res).items
" echo items
call vundle#scripts#view('search', info, vundle#search#bundle_names(items))
echo len(items).' plugins found'
else
call vundle#scripts#view('search', info, ['"An error running query'])
endif
redraw
endf

" ---------------------------------------------------------------------------
" Create a list of 'Plugin ...' lines from a list of bundle names.
"
" names -- a list of names (strings) of plugins
" return -- a list of 'Plugin ...' lines suitable to be written to a buffer
" ---------------------------------------------------------------------------
func! vundle#search#bundle_names(items)
let r = []
for item in a:items
call add(r, printf("Plugin '%s' \" %s", item.full_name, item.description))
endfo
return r
endf

" ---------------------------------------------------------------------------
"
" to -- the filename (string) to save the database to
" url -- the request url
" return -- 0 on success, 1 if an error occurred
" ---------------------------------------------------------------------------

func! s:search(url)
let url = vundle#installer#shellesc(a:url)

if executable("curl")
let cmd = 'curl --fail -s '.l:url
elseif executable("wget")
let cmd = 'wget -q -O - '.l:url
else
echoerr 'Error curl or wget is not available!'
return [1]
endif

let response = system(cmd)

if (0 != v:shell_error)
echoerr 'Error fetching scripts!'
endif
return [v:shell_error, response]
endf

let s:search_url = 'https://api.github.com/search/repositories?q=language:VimL+user:vim-scripts'

" vim: set expandtab sts=2 ts=2 sw=2 tw=78 norl: