Code cleanup: reuse s:trim() when possible
This commit is contained in:
parent
d690f8d576
commit
c4b4aa8f07
1 changed files with 11 additions and 12 deletions
23
plug.vim
23
plug.vim
|
@ -195,14 +195,17 @@ function! plug#end()
|
||||||
syntax on
|
syntax on
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
function! s:trim(str)
|
||||||
|
return substitute(a:str, '[\/]\+$', '', '')
|
||||||
|
endfunction
|
||||||
|
|
||||||
if s:is_win
|
if s:is_win
|
||||||
function! s:rtp(spec)
|
function! s:rtp(spec)
|
||||||
let rtp = s:dirpath(a:spec.dir . get(a:spec, 'rtp', ''))
|
return s:path(a:spec.dir . get(a:spec, 'rtp', ''))
|
||||||
return substitute(rtp, '\\*$', '', '')
|
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:path(path)
|
function! s:path(path)
|
||||||
return substitute(substitute(a:path, '/', '\', 'g'), '[/\\]*$', '', '')
|
return s:trim(substitute(a:path, '/', '\', 'g'))
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:dirpath(path)
|
function! s:dirpath(path)
|
||||||
|
@ -214,11 +217,11 @@ else
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:path(path)
|
function! s:path(path)
|
||||||
return substitute(a:path, '[/\\]*$', '', '')
|
return s:trim(a:path)
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:dirpath(path)
|
function! s:dirpath(path)
|
||||||
return s:path(a:path) . '/'
|
return s:trim(a:path) . '/'
|
||||||
endfunction
|
endfunction
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
@ -300,7 +303,7 @@ function! s:add(force, repo, ...)
|
||||||
endif
|
endif
|
||||||
|
|
||||||
try
|
try
|
||||||
let repo = s:trim_trailing_slashes(a:repo)
|
let repo = s:trim(a:repo)
|
||||||
let name = s:extract_name(repo)
|
let name = s:extract_name(repo)
|
||||||
if !a:force && has_key(g:plugs, name)
|
if !a:force && has_key(g:plugs, name)
|
||||||
let s:extended[name] = g:plugs[name]
|
let s:extended[name] = g:plugs[name]
|
||||||
|
@ -355,12 +358,8 @@ function! s:infer_properties(name, repo)
|
||||||
return properties
|
return properties
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:trim_trailing_slashes(str)
|
|
||||||
return substitute(a:str, '[/\\]*$', '', '')
|
|
||||||
endfunction
|
|
||||||
|
|
||||||
function! s:extract_name(repo)
|
function! s:extract_name(repo)
|
||||||
return substitute(split(a:repo, '/')[-1], '\.git$', '', '')
|
return substitute(split(a:repo, '[\/]\+')[-1], '\.git$', '', '')
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:is_local_plug(repo)
|
function! s:is_local_plug(repo)
|
||||||
|
@ -678,7 +677,7 @@ function! s:update_serial(pull, todo)
|
||||||
\ printf('git clone --recursive %s -b %s %s 2>&1 && cd %s && git submodule update --init --recursive 2>&1',
|
\ printf('git clone --recursive %s -b %s %s 2>&1 && cd %s && git submodule update --init --recursive 2>&1',
|
||||||
\ s:shellesc(spec.uri),
|
\ s:shellesc(spec.uri),
|
||||||
\ s:shellesc(spec.branch),
|
\ s:shellesc(spec.branch),
|
||||||
\ s:shellesc(substitute(spec.dir, '[\/]\+$', '', '')),
|
\ s:shellesc(s:trim(spec.dir)),
|
||||||
\ s:shellesc(spec.dir)))
|
\ s:shellesc(spec.dir)))
|
||||||
let error = v:shell_error != 0
|
let error = v:shell_error != 0
|
||||||
if !error | let s:prev_update.new[name] = 1 | endif
|
if !error | let s:prev_update.new[name] = 1 | endif
|
||||||
|
|
Loading…
Reference in a new issue