Last active
January 27, 2022 06:08
-
-
Save MattSPalmer/19eae83b61405d7bd1c0ead0ca824531 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function nvim_packer_restart() { | |
nvim "$@" | |
if [[ -e "$TMPDIR""packer_compile_at_start" ]]; then | |
nvim_packer_restart "$0" | |
fi | |
} | |
alias nvim='nvim_packer_restart' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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