feat(core): Add CosmicUpdate, CosmicReload, CosmicReloadConfig commands
This commit is contained in:
parent
0e578c1d03
commit
6c50df36e9
3 changed files with 61 additions and 0 deletions
5
lua/cosmic/core/commands.lua
Normal file
5
lua/cosmic/core/commands.lua
Normal file
|
@ -0,0 +1,5 @@
|
|||
vim.cmd([[
|
||||
command! CosmicUpdate lua require('cosmic.utils').update()
|
||||
command! CosmicReloadConfig lua require('cosmic.utils').reload_user_config()
|
||||
command! CosmicReload lua require('cosmic.utils').reload_cosmic()
|
||||
]])
|
|
@ -2,6 +2,7 @@ local cosmic_modules = {
|
|||
'cosmic.disabled',
|
||||
'cosmic.pluginsInit',
|
||||
'cosmic.compiled',
|
||||
'cosmic.core.commands',
|
||||
'cosmic.editor',
|
||||
'cosmic.mappings',
|
||||
'cosmic.core.theme.highlights',
|
||||
|
|
|
@ -47,4 +47,59 @@ function M.get_active_lsp_client_names()
|
|||
return client_names
|
||||
end
|
||||
|
||||
local function reload(module_pattern)
|
||||
for module, _ in pairs(package.loaded) do
|
||||
if module:match(module_pattern) then
|
||||
package.loaded[module] = nil
|
||||
require(module)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function M.reload_user_config()
|
||||
reload('cosmic.config')
|
||||
end
|
||||
|
||||
function M.reload_cosmic()
|
||||
reload('cosmic')
|
||||
end
|
||||
|
||||
function M.get_install_dir()
|
||||
local config_dir = os.getenv('COSMICNVIM_INSTALL_DIR')
|
||||
if not config_dir then
|
||||
return vim.fn.stdpath('config')
|
||||
end
|
||||
return config_dir
|
||||
end
|
||||
|
||||
-- update instance of CosmicNvim
|
||||
function M.update()
|
||||
local Job = require('plenary.job')
|
||||
local path = M.get_install_dir()
|
||||
local err = false
|
||||
|
||||
Job
|
||||
:new({
|
||||
command = 'git',
|
||||
args = { 'pull' },
|
||||
cwd = path,
|
||||
on_exit = function()
|
||||
if not err then
|
||||
vim.notify(
|
||||
'Please restart CosmicNvim and run `:PackerSync`',
|
||||
vim.log.levels.INFO,
|
||||
{ title = 'CosmicNvim Updated!', timeout = 30000 }
|
||||
)
|
||||
end
|
||||
end,
|
||||
on_stderr = function(_, return_val)
|
||||
err = return_val
|
||||
vim.notify(err, vim.log.levels.ERROR, {
|
||||
title = 'CosmicNvim Update Failed!',
|
||||
})
|
||||
end,
|
||||
})
|
||||
:sync() -- or start()
|
||||
end
|
||||
|
||||
return M
|
||||
|
|
Loading…
Add table
Reference in a new issue