-
Notifications
You must be signed in to change notification settings - Fork 0
/
manager.vim
executable file
·71 lines (57 loc) · 1.67 KB
/
manager.vim
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
" chop given url to github repository name
function! s:get_repo_name_from_url(repo_url) abort
let l:pattern = '\([^/]\+\)$'
let l:repo = matchstr(a:repo_url, l:pattern)
return l:repo
endfunction
function! s:install_plugin() abort
for l:repo_url in s:repo_urls
let l:repo = s:get_repo_name_from_url(l:repo_url)
let l:clone_dir = s:path .. 'plugins/' .. l:repo
" if repo not installed
if !isdirectory(expand(l:clone_dir))
let l:command = 'git clone' .. ' ' .. l:repo_url .. ' ' .. l:clone_dir
echo system(l:command)
endif
"let &packpath .= ',' . l:clone_dir
let &runtimepath .= ',' . l:clone_dir
endfor
endfunction
function! s:uninstall_plugin()
let l:ls = 'ls' .. ' ' .. s:path .. 'plugins'
let l:result = system(l:ls)
let l:repos_installed = split(l:result, '\n')
let l:repos_wont_dissapear = []
for l:repo_url in s:repo_urls
call add(l:repos_wont_dissapear, s:get_repo_name_from_url(l:repo_url))
endfor
for l:repo in l:repos_installed
if index(l:repos_wont_dissapear, l:repo) ==# -1
let l:repo_dir = s:path .. 'plugins/' .. l:repo
let l:command = 'rm -rf' .. ' ' .. l:repo_dir
echo system(l:command)
endif
endfor
endfunction
function! s:make_url_array()
let l:repo_urls = readfile(s:path .. 'repos.vim')
let l:i = 0
for l:item in l:repo_urls
if l:item !~ '^"' && l:item != ''
let l:repo_urls[i] = l:item
let l:i += 1
endif
endfor
for i in range(1, len(l:repo_urls)-i)
call remove(l:repo_urls, -1)
endfor
return l:repo_urls
endfunction
if has('nvim')
let s:path = expand('~/.config/nvim/')
else
let s:path = expand('~/.vim/')
endif
let s:repo_urls = s:make_url_array()
call s:install_plugin()
call s:uninstall_plugin()