Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3e3fb7141e | ||
|
|
2afca7e6c3 |
+123
-4
@@ -19,9 +19,6 @@ if empty(glob(data_dir . '/autoload/plug.vim'))
|
|||||||
endif
|
endif
|
||||||
call plug#begin()
|
call plug#begin()
|
||||||
|
|
||||||
" Warn about plugin updates
|
|
||||||
Plug 'semanser/vim-outdated-plugins'
|
|
||||||
|
|
||||||
" Powerline replacement
|
" Powerline replacement
|
||||||
Plug 'vim-airline/vim-airline'
|
Plug 'vim-airline/vim-airline'
|
||||||
Plug 'vim-airline/vim-airline-themes'
|
Plug 'vim-airline/vim-airline-themes'
|
||||||
@@ -76,6 +73,129 @@ Plug 'fatih/vim-go'
|
|||||||
|
|
||||||
call plug#end()
|
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 = { 'ionice', '-c', '3', 'nice', '-n', '10', '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
|
" Run PlugInstall if there are missing plugins
|
||||||
autocmd VimEnter * if len(filter(values(g:plugs), '!isdirectory(v:val.dir)'))
|
autocmd VimEnter * if len(filter(values(g:plugs), '!isdirectory(v:val.dir)'))
|
||||||
\| PlugInstall --sync | source $MYVIMRC
|
\| PlugInstall --sync | source $MYVIMRC
|
||||||
@@ -278,4 +398,3 @@ if filereadable(expand("~/python-envs/neovim/bin/python3"))
|
|||||||
else
|
else
|
||||||
let g:python3_host_prog="/usr/bin/python3"
|
let g:python3_host_prog="/usr/bin/python3"
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user