mirror of
https://github.com/junegunn/vim-plug.git
synced 2026-02-19 11:34:12 +08:00
Compare commits
10 Commits
bfa00760ca
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
34467fc07d | ||
|
|
d72ac8734f | ||
|
|
60dd7a5eaf | ||
|
|
3f17a5cc3d | ||
|
|
904dac1530 | ||
|
|
baa66bcf34 | ||
|
|
cdea0244a5 | ||
|
|
9ef7739c81 | ||
|
|
7cadca537e | ||
|
|
a7d4a73dd6 |
18
README.md
18
README.md
@@ -1,21 +1,3 @@
|
|||||||
<div align="center">
|
|
||||||
<sup>Special thanks to:</sup>
|
|
||||||
<br>
|
|
||||||
<br>
|
|
||||||
<a href="https://warp.dev/?utm_source=github&utm_medium=referral&utm_campaign=vimplug_20240209">
|
|
||||||
<div>
|
|
||||||
<img src="https://raw.githubusercontent.com/junegunn/i/master/warp.png" width="300" alt="Warp">
|
|
||||||
</div>
|
|
||||||
<b>Warp is a modern, Rust-based terminal with AI built in so you and your team can build great software, faster.</b>
|
|
||||||
<div>
|
|
||||||
<sup>Visit warp.dev to learn more.</sup>
|
|
||||||
</div>
|
|
||||||
</a>
|
|
||||||
<br>
|
|
||||||
<hr>
|
|
||||||
</div>
|
|
||||||
<br>
|
|
||||||
|
|
||||||
<h1 title="vim-plug">
|
<h1 title="vim-plug">
|
||||||
<picture>
|
<picture>
|
||||||
<source media="(prefers-color-scheme: dark)" srcset="./plug-dark.png">
|
<source media="(prefers-color-scheme: dark)" srcset="./plug-dark.png">
|
||||||
|
|||||||
96
plug.vim
96
plug.vim
@@ -68,6 +68,7 @@ let s:mac_gui = has('gui_macvim') && has('gui_running')
|
|||||||
let s:is_win = has('win32')
|
let s:is_win = has('win32')
|
||||||
let s:nvim = has('nvim-0.2') || (has('nvim') && exists('*jobwait') && !s:is_win)
|
let s:nvim = has('nvim-0.2') || (has('nvim') && exists('*jobwait') && !s:is_win)
|
||||||
let s:vim8 = has('patch-8.0.0039') && exists('*job_start')
|
let s:vim8 = has('patch-8.0.0039') && exists('*job_start')
|
||||||
|
let s:shell_error = 0
|
||||||
if s:is_win && &shellslash
|
if s:is_win && &shellslash
|
||||||
set noshellslash
|
set noshellslash
|
||||||
let s:me = resolve(expand('<sfile>:p'))
|
let s:me = resolve(expand('<sfile>:p'))
|
||||||
@@ -170,7 +171,7 @@ function! s:git_origin_branch(spec)
|
|||||||
|
|
||||||
" The command may not return the name of a branch in detached HEAD state
|
" The command may not return the name of a branch in detached HEAD state
|
||||||
let result = s:lines(s:system('git symbolic-ref --short HEAD', a:spec.dir))
|
let result = s:lines(s:system('git symbolic-ref --short HEAD', a:spec.dir))
|
||||||
return v:shell_error ? '' : result[-1]
|
return s:shell_error ? '' : result[-1]
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
if s:is_win
|
if s:is_win
|
||||||
@@ -372,8 +373,10 @@ function! plug#end()
|
|||||||
|
|
||||||
for [cmd, names] in items(lod.cmd)
|
for [cmd, names] in items(lod.cmd)
|
||||||
execute printf(
|
execute printf(
|
||||||
\ 'command! -nargs=* -range -bang -complete=file %s call s:lod_cmd(%s, "<bang>", <line1>, <line2>, <q-args>, %s)',
|
\ has('patch-7.4.1898')
|
||||||
\ cmd, string(cmd), string(names))
|
\ ? 'command! -nargs=* -range -bang -complete=file %s call s:lod_cmd(%s, "<bang>", <line1>, <line2>, <q-args>, <q-mods> ,%s)'
|
||||||
|
\ : 'command! -nargs=* -range -bang -complete=file %s call s:lod_cmd(%s, "<bang>", <line1>, <line2>, <q-args>, %s)'
|
||||||
|
\ , cmd, string(cmd), string(names))
|
||||||
endfor
|
endfor
|
||||||
|
|
||||||
for [map, names] in items(lod.map)
|
for [map, names] in items(lod.map)
|
||||||
@@ -651,11 +654,19 @@ function! s:lod_ft(pat, names)
|
|||||||
call s:doautocmd('filetypeindent', 'FileType')
|
call s:doautocmd('filetypeindent', 'FileType')
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
if has('patch-7.4.1898')
|
||||||
|
function! s:lod_cmd(cmd, bang, l1, l2, args, mods, names)
|
||||||
|
call s:lod(a:names, ['ftdetect', 'after/ftdetect', 'plugin', 'after/plugin'])
|
||||||
|
call s:dobufread(a:names)
|
||||||
|
execute printf('%s %s%s%s %s', a:mods, (a:l1 == a:l2 ? '' : (a:l1.','.a:l2)), a:cmd, a:bang, a:args)
|
||||||
|
endfunction
|
||||||
|
else
|
||||||
function! s:lod_cmd(cmd, bang, l1, l2, args, names)
|
function! s:lod_cmd(cmd, bang, l1, l2, args, names)
|
||||||
call s:lod(a:names, ['ftdetect', 'after/ftdetect', 'plugin', 'after/plugin'])
|
call s:lod(a:names, ['ftdetect', 'after/ftdetect', 'plugin', 'after/plugin'])
|
||||||
call s:dobufread(a:names)
|
call s:dobufread(a:names)
|
||||||
execute printf('%s%s%s %s', (a:l1 == a:l2 ? '' : (a:l1.','.a:l2)), a:cmd, a:bang, a:args)
|
execute printf('%s%s%s %s', (a:l1 == a:l2 ? '' : (a:l1.','.a:l2)), a:cmd, a:bang, a:args)
|
||||||
endfunction
|
endfunction
|
||||||
|
endif
|
||||||
|
|
||||||
function! s:lod_map(map, names, with_prefix, prefix)
|
function! s:lod_map(map, names, with_prefix, prefix)
|
||||||
call s:lod(a:names, ['ftdetect', 'after/ftdetect', 'plugin', 'after/plugin'])
|
call s:lod(a:names, ['ftdetect', 'after/ftdetect', 'plugin', 'after/plugin'])
|
||||||
@@ -1075,15 +1086,19 @@ function! s:hash_match(a, b)
|
|||||||
return stridx(a:a, a:b) == 0 || stridx(a:b, a:a) == 0
|
return stridx(a:a, a:b) == 0 || stridx(a:b, a:a) == 0
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
function! s:disable_credential_helper()
|
||||||
|
return s:git_version_requirement(2) && get(g:, 'plug_disable_credential_helper', 1)
|
||||||
|
endfunction
|
||||||
|
|
||||||
function! s:checkout(spec)
|
function! s:checkout(spec)
|
||||||
let sha = a:spec.commit
|
let sha = a:spec.commit
|
||||||
let output = s:git_revision(a:spec.dir)
|
let output = s:git_revision(a:spec.dir)
|
||||||
let error = 0
|
let error = 0
|
||||||
if !empty(output) && !s:hash_match(sha, s:lines(output)[0])
|
if !empty(output) && !s:hash_match(sha, s:lines(output)[0])
|
||||||
let credential_helper = s:git_version_requirement(2) ? '-c credential.helper= ' : ''
|
let credential_helper = s:disable_credential_helper() ? '-c credential.helper= ' : ''
|
||||||
let output = s:system(
|
let output = s:system(
|
||||||
\ 'git '.credential_helper.'fetch --depth 999999 && git checkout '.plug#shellescape(sha).' --', a:spec.dir)
|
\ 'git '.credential_helper.'fetch --depth 999999 && git checkout '.plug#shellescape(sha).' --', a:spec.dir)
|
||||||
let error = v:shell_error
|
let error = s:shell_error
|
||||||
endif
|
endif
|
||||||
return [output, error]
|
return [output, error]
|
||||||
endfunction
|
endfunction
|
||||||
@@ -1289,7 +1304,7 @@ function! s:update_finish()
|
|||||||
let tag = spec.tag
|
let tag = spec.tag
|
||||||
if tag =~ '\*'
|
if tag =~ '\*'
|
||||||
let tags = s:lines(s:system('git tag --list '.plug#shellescape(tag).' --sort -version:refname 2>&1', spec.dir))
|
let tags = s:lines(s:system('git tag --list '.plug#shellescape(tag).' --sort -version:refname 2>&1', spec.dir))
|
||||||
if !v:shell_error && !empty(tags)
|
if !s:shell_error && !empty(tags)
|
||||||
let tag = tags[0]
|
let tag = tags[0]
|
||||||
call s:log4(name, printf('Latest tag for %s -> %s', spec.tag, tag))
|
call s:log4(name, printf('Latest tag for %s -> %s', spec.tag, tag))
|
||||||
call append(3, '')
|
call append(3, '')
|
||||||
@@ -1297,7 +1312,7 @@ function! s:update_finish()
|
|||||||
endif
|
endif
|
||||||
call s:log4(name, 'Checking out '.tag)
|
call s:log4(name, 'Checking out '.tag)
|
||||||
let out = s:system('git checkout -q '.plug#shellescape(tag).' -- 2>&1', spec.dir)
|
let out = s:system('git checkout -q '.plug#shellescape(tag).' -- 2>&1', spec.dir)
|
||||||
let error = v:shell_error
|
let error = s:shell_error
|
||||||
endif
|
endif
|
||||||
if !error && filereadable(spec.dir.'/.gitmodules') &&
|
if !error && filereadable(spec.dir.'/.gitmodules') &&
|
||||||
\ (s:update.force || has_key(s:update.new, name) || s:is_updated(spec.dir))
|
\ (s:update.force || has_key(s:update.new, name) || s:is_updated(spec.dir))
|
||||||
@@ -1305,7 +1320,7 @@ function! s:update_finish()
|
|||||||
let out .= s:bang('git submodule update --init --recursive'.s:submodule_opt.' 2>&1', spec.dir)
|
let out .= s:bang('git submodule update --init --recursive'.s:submodule_opt.' 2>&1', spec.dir)
|
||||||
let error = v:shell_error
|
let error = v:shell_error
|
||||||
endif
|
endif
|
||||||
let msg = s:format_message(v:shell_error ? 'x': '-', name, out)
|
let msg = s:format_message(error ? 'x': '-', name, out)
|
||||||
if error
|
if error
|
||||||
call add(s:update.errors, name)
|
call add(s:update.errors, name)
|
||||||
call s:regress_bar()
|
call s:regress_bar()
|
||||||
@@ -1466,7 +1481,7 @@ function! s:spawn(name, spec, queue, opts)
|
|||||||
endif
|
endif
|
||||||
else
|
else
|
||||||
let job.lines = s:lines(call('s:system', has_key(a:opts, 'dir') ? [argv, a:opts.dir] : [argv]))
|
let job.lines = s:lines(call('s:system', has_key(a:opts, 'dir') ? [argv, a:opts.dir] : [argv]))
|
||||||
let job.error = v:shell_error != 0
|
let job.error = s:shell_error != 0
|
||||||
let job.running = 0
|
let job.running = 0
|
||||||
endif
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
@@ -1589,7 +1604,7 @@ while 1 " Without TCO, Vim stack is bound to explode
|
|||||||
let [error, _] = s:git_validate(spec, 0)
|
let [error, _] = s:git_validate(spec, 0)
|
||||||
if empty(error)
|
if empty(error)
|
||||||
if pull
|
if pull
|
||||||
let cmd = s:git_version_requirement(2) ? ['git', '-c', 'credential.helper=', 'fetch'] : ['git', 'fetch']
|
let cmd = s:disable_credential_helper() ? ['git', '-c', 'credential.helper=', 'fetch'] : ['git', 'fetch']
|
||||||
if has_tag && !empty(globpath(spec.dir, '.git/shallow'))
|
if has_tag && !empty(globpath(spec.dir, '.git/shallow'))
|
||||||
call extend(cmd, ['--depth', '99999999'])
|
call extend(cmd, ['--depth', '99999999'])
|
||||||
endif
|
endif
|
||||||
@@ -2320,6 +2335,22 @@ function! s:with_cd(cmd, dir, ...)
|
|||||||
return printf('%s %s %s %s', cd, plug#shellescape(a:dir, {'script': script, 'shell': &shell}), sep, a:cmd)
|
return printf('%s %s %s %s', cd, plug#shellescape(a:dir, {'script': script, 'shell': &shell}), sep, a:cmd)
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
function! s:system_job(cmd) abort
|
||||||
|
let tmp = tempname()
|
||||||
|
let job = job_start(['/bin/sh', '-c', a:cmd], {
|
||||||
|
\ 'out_io': 'file',
|
||||||
|
\ 'out_name': tmp,
|
||||||
|
\ 'err_io': 'out',
|
||||||
|
\})
|
||||||
|
while job_status(job) ==# 'run'
|
||||||
|
sleep 1m
|
||||||
|
endwhile
|
||||||
|
let s:shell_error = job_info(job).exitval
|
||||||
|
let result = filereadable(tmp) ? join(readfile(tmp, 'b'), "\n") : ''
|
||||||
|
silent! call delete(tmp)
|
||||||
|
return result
|
||||||
|
endfunction
|
||||||
|
|
||||||
function! s:system(cmd, ...)
|
function! s:system(cmd, ...)
|
||||||
let batchfile = ''
|
let batchfile = ''
|
||||||
try
|
try
|
||||||
@@ -2329,7 +2360,9 @@ function! s:system(cmd, ...)
|
|||||||
" but it cannot set the working directory for the command.
|
" but it cannot set the working directory for the command.
|
||||||
" Assume that the command does not rely on the shell.
|
" Assume that the command does not rely on the shell.
|
||||||
if has('nvim') && a:0 == 0
|
if has('nvim') && a:0 == 0
|
||||||
return system(a:cmd)
|
let ret = system(a:cmd)
|
||||||
|
let s:shell_error = v:shell_error
|
||||||
|
return ret
|
||||||
endif
|
endif
|
||||||
let cmd = join(map(copy(a:cmd), 'plug#shellescape(v:val, {"shell": &shell, "script": 0})'))
|
let cmd = join(map(copy(a:cmd), 'plug#shellescape(v:val, {"shell": &shell, "script": 0})'))
|
||||||
if s:is_powershell(&shell)
|
if s:is_powershell(&shell)
|
||||||
@@ -2344,7 +2377,12 @@ function! s:system(cmd, ...)
|
|||||||
if s:is_win && type(a:cmd) != s:TYPE.list
|
if s:is_win && type(a:cmd) != s:TYPE.list
|
||||||
let [batchfile, cmd] = s:batchfile(cmd)
|
let [batchfile, cmd] = s:batchfile(cmd)
|
||||||
endif
|
endif
|
||||||
return system(cmd)
|
if s:vim8 && has('gui_running') && !s:is_win
|
||||||
|
return s:system_job(cmd)
|
||||||
|
endif
|
||||||
|
let ret = system(cmd)
|
||||||
|
let s:shell_error = v:shell_error
|
||||||
|
return ret
|
||||||
finally
|
finally
|
||||||
let [&shell, &shellcmdflag, &shellredir] = [sh, shellcmdflag, shrd]
|
let [&shell, &shellcmdflag, &shellredir] = [sh, shellcmdflag, shrd]
|
||||||
if s:is_win && filereadable(batchfile)
|
if s:is_win && filereadable(batchfile)
|
||||||
@@ -2355,7 +2393,7 @@ endfunction
|
|||||||
|
|
||||||
function! s:system_chomp(...)
|
function! s:system_chomp(...)
|
||||||
let ret = call('s:system', a:000)
|
let ret = call('s:system', a:000)
|
||||||
return v:shell_error ? '' : substitute(ret, '\n$', '', '')
|
return s:shell_error ? '' : substitute(ret, '\n$', '', '')
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:git_validate(spec, check_branch)
|
function! s:git_validate(spec, check_branch)
|
||||||
@@ -2369,7 +2407,9 @@ function! s:git_validate(spec, check_branch)
|
|||||||
let err = join(['Invalid URI: '.remote,
|
let err = join(['Invalid URI: '.remote,
|
||||||
\ 'Expected: '.a:spec.uri,
|
\ 'Expected: '.a:spec.uri,
|
||||||
\ 'PlugClean required.'], "\n")
|
\ 'PlugClean required.'], "\n")
|
||||||
elseif a:check_branch && has_key(a:spec, 'commit')
|
elseif !a:check_branch
|
||||||
|
return ['', 0]
|
||||||
|
elseif has_key(a:spec, 'commit')
|
||||||
let sha = s:git_revision(a:spec.dir)
|
let sha = s:git_revision(a:spec.dir)
|
||||||
if empty(sha)
|
if empty(sha)
|
||||||
let err = join(add(result, 'PlugClean required.'), "\n")
|
let err = join(add(result, 'PlugClean required.'), "\n")
|
||||||
@@ -2378,18 +2418,16 @@ function! s:git_validate(spec, check_branch)
|
|||||||
\ a:spec.commit[:6], sha[:6]),
|
\ a:spec.commit[:6], sha[:6]),
|
||||||
\ 'PlugUpdate required.'], "\n")
|
\ 'PlugUpdate required.'], "\n")
|
||||||
endif
|
endif
|
||||||
elseif a:check_branch
|
elseif has_key(a:spec, 'tag')
|
||||||
let current_branch = result[0]
|
|
||||||
" Check tag
|
|
||||||
let origin_branch = s:git_origin_branch(a:spec)
|
|
||||||
if has_key(a:spec, 'tag')
|
|
||||||
let tag = s:system_chomp('git describe --exact-match --tags HEAD 2>&1', a:spec.dir)
|
let tag = s:system_chomp('git describe --exact-match --tags HEAD 2>&1', a:spec.dir)
|
||||||
if a:spec.tag !=# tag && a:spec.tag !~ '\*'
|
if a:spec.tag !=# tag && a:spec.tag !~ '\*'
|
||||||
let err = printf('Invalid tag: %s (expected: %s). Try PlugUpdate.',
|
let err = printf('Invalid tag: %s (expected: %s). Try PlugUpdate.',
|
||||||
\ (empty(tag) ? 'N/A' : tag), a:spec.tag)
|
\ (empty(tag) ? 'N/A' : tag), a:spec.tag)
|
||||||
endif
|
endif
|
||||||
" Check branch
|
elseif a:check_branch
|
||||||
elseif origin_branch !=# current_branch
|
let current_branch = result[0]
|
||||||
|
let origin_branch = s:git_origin_branch(a:spec)
|
||||||
|
if origin_branch !=# current_branch
|
||||||
let err = printf('Invalid branch: %s (expected: %s). Try PlugUpdate.',
|
let err = printf('Invalid branch: %s (expected: %s). Try PlugUpdate.',
|
||||||
\ current_branch, origin_branch)
|
\ current_branch, origin_branch)
|
||||||
endif
|
endif
|
||||||
@@ -2398,7 +2436,7 @@ function! s:git_validate(spec, check_branch)
|
|||||||
\ 'git', 'rev-list', '--count', '--left-right',
|
\ 'git', 'rev-list', '--count', '--left-right',
|
||||||
\ printf('HEAD...origin/%s', origin_branch)
|
\ printf('HEAD...origin/%s', origin_branch)
|
||||||
\ ], a:spec.dir)), '\t')
|
\ ], a:spec.dir)), '\t')
|
||||||
if v:shell_error || len(ahead_behind) != 2
|
if s:shell_error || len(ahead_behind) != 2
|
||||||
let err = "Failed to compare with the origin. The default branch might have changed.\nPlugClean required."
|
let err = "Failed to compare with the origin. The default branch might have changed.\nPlugClean required."
|
||||||
else
|
else
|
||||||
let [ahead, behind] = ahead_behind
|
let [ahead, behind] = ahead_behind
|
||||||
@@ -2548,7 +2586,7 @@ function! s:upgrade()
|
|||||||
|
|
||||||
try
|
try
|
||||||
let out = s:system(['git', 'clone', '--depth', '1', s:plug_src, tmp])
|
let out = s:system(['git', 'clone', '--depth', '1', s:plug_src, tmp])
|
||||||
if v:shell_error
|
if s:shell_error
|
||||||
return s:err('Error upgrading vim-plug: '. out)
|
return s:err('Error upgrading vim-plug: '. out)
|
||||||
endif
|
endif
|
||||||
|
|
||||||
@@ -2859,17 +2897,5 @@ if exists('g:plugs')
|
|||||||
call s:define_commands()
|
call s:define_commands()
|
||||||
endif
|
endif
|
||||||
|
|
||||||
function! plug#plugin_info(name) abort
|
|
||||||
return get(s:loaded, a:name, {})
|
|
||||||
endfunction
|
|
||||||
|
|
||||||
function! plug#loaded() abort
|
|
||||||
return keys(filter(copy(s:loaded), { k, v -> v }))
|
|
||||||
endfunction
|
|
||||||
|
|
||||||
function! plug#not_loaded() abort
|
|
||||||
return keys(filter(copy(s:loaded), { k, v -> !v }))
|
|
||||||
endfunction
|
|
||||||
|
|
||||||
let &cpo = s:cpo_save
|
let &cpo = s:cpo_save
|
||||||
unlet s:cpo_save
|
unlet s:cpo_save
|
||||||
|
|||||||
Reference in New Issue
Block a user