nvim/lua/cosmic/utils/cosmic.lua
2022-12-30 09:47:16 -08:00

47 lines
1.1 KiB
Lua

local M = {}
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
function M.sync_plugins()
vim.cmd(':Lazy sync')
end
-- update instance of CosmicNvim
function M.update()
local Logger = require('cosmic.utils.logger')
local Job = require('plenary.job')
local path = M.get_install_dir()
local errors = {}
Job
:new({
command = 'git',
args = { 'pull', '--ff-only' },
cwd = path,
on_start = function()
Logger:log('Updating...')
end,
on_exit = function()
if vim.tbl_isempty(errors) then
Logger:log('Updated! Running CosmicReloadSync...')
M.reload_user_config_sync()
else
table.insert(errors, 1, 'Something went wrong! Please pull changes manually.')
table.insert(errors, 2, '')
Logger:error('Update failed!', { timeout = 30000 })
end
end,
on_stderr = function(_, err)
table.insert(errors, err)
end,
})
:sync()
end
return M