Compare commits
3
Commits
f5389de7b8
...
13ffdfdb04
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
13ffdfdb04 | ||
|
|
67885075d3 | ||
|
|
9ffe78362e |
+130
-3
@@ -32,9 +32,6 @@ let g:loaded_perl_provider = 0
|
||||
call plug#begin()
|
||||
|
||||
if !exists('g:vscode')
|
||||
" Warn about plugin updates
|
||||
Plug 'semanser/vim-outdated-plugins'
|
||||
|
||||
" Powerline replacement
|
||||
Plug 'vim-airline/vim-airline'
|
||||
Plug 'vim-airline/vim-airline-themes'
|
||||
@@ -112,6 +109,136 @@ endif
|
||||
|
||||
call plug#end()
|
||||
|
||||
" Check for plugin updates after the editor is responsive.
|
||||
lua << EOF
|
||||
local function check_plugin_updates()
|
||||
local plugins = {}
|
||||
for name, plugin in pairs(vim.g.plugs or {}) do
|
||||
if vim.fn.isdirectory(plugin.dir) == 1 then
|
||||
table.insert(plugins, { name = name, dir = plugin.dir })
|
||||
end
|
||||
end
|
||||
table.sort(plugins, function(a, b) return a.name < b.name end)
|
||||
|
||||
local next_plugin = 1
|
||||
local active = 0
|
||||
local finished = 0
|
||||
local failures = 0
|
||||
local updates = {}
|
||||
local concurrency = 2
|
||||
|
||||
local function git_command(args)
|
||||
local command = {}
|
||||
if vim.fn.executable('ionice') == 1 then
|
||||
vim.list_extend(command, { 'ionice', '-c', '3' })
|
||||
end
|
||||
if vim.fn.executable('nice') == 1 then
|
||||
vim.list_extend(command, { 'nice', '-n', '10' })
|
||||
end
|
||||
table.insert(command, 'git')
|
||||
vim.list_extend(command, args)
|
||||
return command
|
||||
end
|
||||
|
||||
local function set_airline_status(message)
|
||||
vim.g.plugin_update_status = message
|
||||
local marker = '%{get(g:,"plugin_update_status","")}'
|
||||
local warning = vim.g.airline_section_warning or ''
|
||||
if not string.find(warning, 'plugin_update_status', 1, true) then
|
||||
vim.g.airline_section_warning = warning .. ' ' .. marker
|
||||
end
|
||||
if vim.fn.exists(':AirlineRefresh') == 2 then
|
||||
vim.cmd('AirlineRefresh')
|
||||
end
|
||||
end
|
||||
|
||||
local function report()
|
||||
if #updates > 0 then
|
||||
set_airline_status(string.format('[updates: %d]', #updates))
|
||||
local message = string.format(
|
||||
'%d plugin update%s available: %s',
|
||||
#updates,
|
||||
#updates == 1 and '' or 's',
|
||||
table.concat(updates, ', ')
|
||||
)
|
||||
if failures > 0 then
|
||||
message = message .. string.format(' (%d check%s failed)', failures, failures == 1 and '' or 's')
|
||||
end
|
||||
vim.notify(message, failures > 0 and vim.log.levels.WARN or vim.log.levels.INFO)
|
||||
elseif failures > 0 then
|
||||
set_airline_status('[update check failed]')
|
||||
vim.notify(
|
||||
string.format('Plugin update check incomplete: %d check%s failed', failures, failures == 1 and '' or 's'),
|
||||
vim.log.levels.WARN
|
||||
)
|
||||
else
|
||||
set_airline_status('')
|
||||
vim.notify('All plugins up-to-date', vim.log.levels.INFO)
|
||||
end
|
||||
end
|
||||
|
||||
local pump
|
||||
local function complete_one()
|
||||
active = active - 1
|
||||
finished = finished + 1
|
||||
if finished == #plugins then
|
||||
report()
|
||||
else
|
||||
pump()
|
||||
end
|
||||
end
|
||||
|
||||
local function check_one(plugin)
|
||||
active = active + 1
|
||||
vim.system(
|
||||
git_command({ '-C', plugin.dir, 'fetch', '--quiet', '--no-tags', 'origin' }),
|
||||
{ text = true, timeout = 20000 },
|
||||
vim.schedule_wrap(function(fetch_result)
|
||||
if fetch_result.code ~= 0 then
|
||||
failures = failures + 1
|
||||
complete_one()
|
||||
return
|
||||
end
|
||||
|
||||
vim.system(
|
||||
git_command({ '-C', plugin.dir, 'rev-list', '--count', 'HEAD..@{upstream}' }),
|
||||
{ text = true, timeout = 5000 },
|
||||
vim.schedule_wrap(function(count_result)
|
||||
local count = tonumber(vim.trim(count_result.stdout or ''))
|
||||
if count_result.code ~= 0 or count == nil then
|
||||
failures = failures + 1
|
||||
elseif count > 0 then
|
||||
table.insert(updates, plugin.name)
|
||||
end
|
||||
complete_one()
|
||||
end)
|
||||
)
|
||||
end)
|
||||
)
|
||||
end
|
||||
|
||||
pump = function()
|
||||
while active < concurrency and next_plugin <= #plugins do
|
||||
local plugin = plugins[next_plugin]
|
||||
next_plugin = next_plugin + 1
|
||||
check_one(plugin)
|
||||
end
|
||||
end
|
||||
|
||||
if #plugins > 0 then
|
||||
pump()
|
||||
end
|
||||
end
|
||||
|
||||
vim.api.nvim_create_autocmd('VimEnter', {
|
||||
group = vim.api.nvim_create_augroup('plugin_update_check', { clear = true }),
|
||||
once = true,
|
||||
callback = function()
|
||||
vim.defer_fn(check_plugin_updates, 1500)
|
||||
end,
|
||||
})
|
||||
EOF
|
||||
|
||||
" Run PlugInstall if there are missing plugins
|
||||
autocmd VimEnter * if len(filter(values(g:plugs), '!isdirectory(v:val.dir)'))
|
||||
\| PlugInstall --sync | source $MYVIMRC
|
||||
|
||||
Reference in New Issue
Block a user