Change directory structure: user/repo/branch -> user/repo

This commit is contained in:
Junegunn Choi 2013-09-13 12:13:24 +09:00
parent 754abb36a2
commit 9573ec9bd2
2 changed files with 25 additions and 22 deletions

View file

@ -3,19 +3,16 @@ vim-plug
A single-file Vim plugin manager. A single-file Vim plugin manager.
### Wh..why?
... because I can?
### Pros. ### Pros.
- Easier to setup - Easier to setup
- Parallel installation/update (requires +ruby) - Parallel installation/update (requires +ruby)
- Alternative directory structure: user/repo/branch - Alternative directory structure: user/repo
- Make it easier to switch plugins of the same name from different authors
### Cons. ### Cons.
Everything else. - Everything else
### Usage ### Usage

View file

@ -12,6 +12,7 @@
" call plug#init() " call plug#init()
" "
" Plug 'junegunn/seoul256' " Plug 'junegunn/seoul256'
" Plug 'junegunn/vim-easy-align'
" " Plug 'user/repo', 'branch_or_tag' " " Plug 'user/repo', 'branch_or_tag'
" " ... " " ...
" "
@ -56,7 +57,8 @@ function! plug#init(...)
set nocompatible set nocompatible
filetype off filetype off
filetype plugin indent on filetype plugin indent on
let home = a:0 > 0 ? fnamemodify(a:1, ':p') : (split(&rtp, ',')[0].'/plugged') let home = a:0 > 0 ? fnamemodify(a:1, ':p') :
\ get(g:, 'plug_home', split(&rtp, ',')[0].'/plugged')
if !isdirectory(home) if !isdirectory(home)
try try
call mkdir(home, 'p') call mkdir(home, 'p')
@ -71,7 +73,7 @@ function! plug#init(...)
endif endif
let g:plug_home = home let g:plug_home = home
let g:plug = {} let g:plugs = {}
command! -nargs=+ Plug call s:add(<args>) command! -nargs=+ Plug call s:add(<args>)
command! -nargs=* PlugInstall call s:install(<f-args>) command! -nargs=* PlugInstall call s:install(<f-args>)
@ -95,14 +97,14 @@ function! s:add(...)
endif endif
let name = split(plugin, '/')[-1] let name = split(plugin, '/')[-1]
let dir = fnamemodify(join([g:plug_home, plugin, branch], '/'), ':p') let dir = fnamemodify(join([g:plug_home, plugin], '/'), ':p')
let uri = 'https://git:@github.com/' . plugin . '.git' let uri = 'https://git:@github.com/' . plugin . '.git'
let spec = { 'name': name, 'dir': dir, 'uri': uri, 'branch': branch } let spec = { 'name': name, 'dir': dir, 'uri': uri, 'branch': branch }
execute "set rtp+=".dir execute "set rtp^=".dir
if isdirectory(dir.'after') if isdirectory(dir.'after')
execute "set rtp+=".dir.'after' execute "set rtp+=".dir.'after'
endif endif
let g:plug[plugin] = spec let g:plugs[plugin] = spec
endfunction endfunction
function! s:install(...) function! s:install(...)
@ -114,7 +116,7 @@ function! s:update(...)
endfunction endfunction
function! s:apply() function! s:apply()
for spec in values(g:plug) for spec in values(g:plugs)
let docd = join([spec.dir, 'doc'], '/') let docd = join([spec.dir, 'doc'], '/')
if isdirectory(docd) if isdirectory(docd)
execute "helptags ". join([spec.dir, 'doc'], '/') execute "helptags ". join([spec.dir, 'doc'], '/')
@ -192,14 +194,14 @@ endfunction
function! s:update_impl(pull, args) function! s:update_impl(pull, args)
if has('ruby') && get(g:, 'plug_parallel', 1) if has('ruby') && get(g:, 'plug_parallel', 1)
let threads = min( let threads = min(
\ [len(g:plug), len(a:args) > 0 ? a:args[0] : get(g:, 'plug_threads', 16)]) \ [len(g:plugs), len(a:args) > 0 ? a:args[0] : get(g:, 'plug_threads', 16)])
else else
let threads = 1 let threads = 1
endif endif
call s:prepare() call s:prepare()
call append(0, 'Updating plugins') call append(0, 'Updating plugins')
call append(1, '['. s:lpad('', len(g:plug)) .']') call append(1, '['. s:lpad('', len(g:plugs)) .']')
normal! 2G normal! 2G
redraw redraw
@ -215,14 +217,17 @@ function! s:update_serial(pull)
let st = reltime() let st = reltime()
let base = g:plug_home let base = g:plug_home
let cnt = 0 let cnt = 0
let total = len(g:plug) let total = len(g:plugs)
for [name, spec] in items(g:plug) for [name, spec] in items(g:plugs)
let cnt += 1 let cnt += 1
let d = shellescape(spec.dir) let d = shellescape(spec.dir)
if isdirectory(spec.dir) if isdirectory(spec.dir)
execute 'cd '.spec.dir execute 'cd '.spec.dir
let result = a:pull ? s:system('git pull 2>&1') : 'Already installed' let result = a:pull ?
\ s:system(
\ printf('git checkout -q %s && git pull origin %s 2>&1',
\ spec.branch, spec.branch)) : 'Already installed'
let error = a:pull ? v:shell_error != 0 : 0 let error = a:pull ? v:shell_error != 0 : 0
else else
if !isdirectory(base) if !isdirectory(base)
@ -256,7 +261,7 @@ function! s:update_parallel(pull, threads)
cd = VIM::evaluate('s:is_win').to_i == 1 ? 'cd /d' : 'cd' cd = VIM::evaluate('s:is_win').to_i == 1 ? 'cd /d' : 'cd'
pull = VIM::evaluate('a:pull').to_i == 1 pull = VIM::evaluate('a:pull').to_i == 1
base = VIM::evaluate('g:plug_home') base = VIM::evaluate('g:plug_home')
all = VIM::evaluate('g:plug') all = VIM::evaluate('g:plugs')
total = all.length total = all.length
cnt = 0 cnt = 0
skip = 'Already installed' skip = 'Already installed'
@ -279,7 +284,9 @@ function! s:update_parallel(pull, threads)
name, dir, uri, branch = pair.last.values_at *%w[name dir uri branch] name, dir, uri, branch = pair.last.values_at *%w[name dir uri branch]
result = result =
if File.directory? dir if File.directory? dir
pull ? `#{cd} #{dir} && git pull 2>&1` : skip pull ?
`#{cd} #{dir} && git checkout -q #{branch} && git pull origin #{branch} 2>&1`
: skip
else else
FileUtils.mkdir_p(base) FileUtils.mkdir_p(base)
`#{cd} #{base} && git clone --recursive #{uri} -b #{branch} #{dir} 2>&1` `#{cd} #{base} && git clone --recursive #{uri} -b #{branch} #{dir} 2>&1`
@ -306,10 +313,9 @@ function! s:clean()
call append(0, 'Removing unused plugins in '.g:plug_home) call append(0, 'Removing unused plugins in '.g:plug_home)
" List of files " List of files
let dirs = map(values(g:plug), 's:path(v:val.dir)') let dirs = map(values(g:plugs), 's:path(v:val.dir)')
let alldirs = dirs + let alldirs = dirs +
\ map(copy(dirs), 'fnamemodify(v:val, ":h")') + \ map(copy(dirs), 'fnamemodify(v:val, ":h")')
\ map(copy(dirs), 'fnamemodify(v:val, ":h:h")')
for dir in dirs for dir in dirs
let alldirs += s:glob_dir(dir) let alldirs += s:glob_dir(dir)
endfor endfor