Skip to content

Instantly share code, notes, and snippets.

@MattSPalmer
Last active January 27, 2022 06:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MattSPalmer/19eae83b61405d7bd1c0ead0ca824531 to your computer and use it in GitHub Desktop.
Save MattSPalmer/19eae83b61405d7bd1c0ead0ca824531 to your computer and use it in GitHub Desktop.
function nvim_packer_restart() {
nvim "$@"
if [[ -e "$TMPDIR""packer_compile_at_start" ]]; then
nvim_packer_restart "$0"
fi
}
alias nvim='nvim_packer_restart'
local packer = require("packer")
local M = {}
local SENTINEL_PATH = os.getenv("TMPDIR") .. "packer_compile_at_start"
local did_restart = function()
local f = io.open(SENTINEL_PATH, "r")
if f ~= nil then
io.close(f)
return true
else
return false
end
end
function _G.restart()
if did_restart() then
return false
end
local f = io.open(SENTINEL_PATH, "w")
f:write("")
f:close()
vim.cmd("qa")
end
local do_startup = function(plugs)
local ok, err = pcall(packer.startup, plugs)
if not ok then
vim.notify(string.format("Bad packer startup: %s", vim.inspect(err)))
end
end
function M.packer_startup(plugs)
do_startup(plugs)
if did_restart() then
_G.do_startup = function()
do_startup(plugs)
os.remove(SENTINEL_PATH)
_G.do_startup = nil
end
vim.cmd([[ autocmd User PackerComplete ++once PackerCompile ]])
vim.cmd([[ autocmd User PackerCompileDone ++once lua do_startup() ]])
packer.install()
end
end
return M
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment