Skip to content

Instantly share code, notes, and snippets.

@Jagua
Last active February 13, 2016 16:49
Show Gist options
  • Save Jagua/0cc9d81d27e5cccf9a0b to your computer and use it in GitHub Desktop.
Save Jagua/0cc9d81d27e5cccf9a0b to your computer and use it in GitHub Desktop.
"
" fetch_ku.vim is a vim file to fetch a vim plugin, vim-ku.
"
" Usage:
" vim -N -u fetch_ku.vim -U NONE --cmd "let g:ku_dir = expand('~/.vim/bundle/vim-ku')"
"
function! s:entries(base, files, result) abort "{{{
let r = []
if type(a:files) == type({})
for i in keys(a:files)
let r += s:entries(a:base . i . '/', a:files[i], a:result)
endfor
elseif type(a:files) == type([])
for i in range(len(a:files))
if type(a:files[i]) == type('')
let r += [a:base . a:files[i]]
elseif type(a:files[i]) == type({})
let r += s:entries(a:base, a:files[i], a:result)
endif
endfor
else
echo 'invalid type : a:files'
endif
return r
endfunction "}}}
function! s:get_urls() abort "{{{
let s:base = 'https://raw.githubusercontent.com/kana/config/master/vim/personal/'
let s:files = {
\ 'doc' : [
\ 'ku-args.txt',
\ 'ku-buffer.txt',
\ 'ku-bundle.txt',
\ 'ku-file.txt',
\ 'ku-history.txt',
\ 'ku-metarw.txt',
\ 'ku-quickfix.txt',
\ 'ku-source.txt',
\ 'ku.txt',
\ ],
\ 'syntax' : [
\ 'ku.vim',
\ ],
\ 'plugin' : [
\ 'ku.vim',
\ ],
\ 'autoload' : [
\ 'ku.vim',
\ {
\ 'ku' : [
\ 'args.vim',
\ 'buffer.vim',
\ 'bundle.vim',
\ 'file.vim',
\ 'history.vim',
\ 'metarw.vim',
\ 'mru.vim',
\ 'myproject.vim',
\ 'quickfix.vim',
\ 'source.vim',
\ ],
\ },
\ ],
\ }
return s:entries(s:base, s:files, [])
endfunction "}}}
function! s:make_cmdln() abort "{{{
let cmdlns = []
let urls = s:get_urls()
for url in urls
let url = substitute(url, '^\(https://.*personal/\)\(.\+\)$',
\ '\=submatch(1)."{".submatch(2)."} -o \"".(has("win32") ? substitute(submatch(2), "/", "\\\\\\\\", "g") : submatch(2))."\""', '')
call add(cmdlns, 'curl --create-dirs ' . url)
endfor
return cmdlns
endfunction "}}}
function! s:fetch_ku(dir) abort "{{{
if !executable('curl')
echo 'not found curl. (required)'
return
end
if empty(a:dir)
echo 'not specified g:ku_dir (see source)'
return
elseif !isdirectory(a:dir)
if exists("*mkdir")
call mkdir(a:dir, 'p')
else
echo 'not found: ' . a:dir
return
endif
endif
let cwd = getcwd()
execute 'lcd' a:dir
for cmdln in s:make_cmdln()
call system(cmdln)
sleep 50m
endfor
execute 'lcd' cwd
echo 'done.'
endfunction "}}}
call s:fetch_ku(get(g:, 'ku_dir', ''))
qall!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment