Packer.nvim: Feature Request: Blocking Install

Created on 6 Feb 2021  路  6Comments  路  Source: wbthomason/packer.nvim

I'm trying to be clever while bootstrapping the first run of neovim to install packer. I'd actually like to block during install so that I don't get any errors when the rest of my config is loaded after kicking off the packer.install().

enhancement help wanted

All 6 comments

Seconding This. What i'd love to do is be able to run nvim --headless +PackerSync +qa in my env installer script.

Making a blocking install is more involved than it seems on its face, because the jobs we rely on are inherently non-blocking. We could use busy-waiting (e.g. a loop until the job done callback gets invoked), but that seems undesirable. I could be wrong, but I don't believe we have access to any of the usual synchronization primitives to block without spinning.

I'll need to think about the best way to do this - contributions or suggestions are welcome!

Note to myself/anyone who wants to take this issue on: vim.wait might provide a good way to make things block without spinning.

I believe these use cases have been addressed at least in part with #259


Bootstrapping packer + plugins in init.lua without errors

local fn = vim.fn

-- Auto install packer.nvim
local install_path = fn.stdpath('data') .. '/site/pack/packer/start/packer.nvim'

if fn.isdirectory(install_path) == 0 then
  fn.system({'git', 'clone', 'https://github.com/wbthomason/packer.nvim', install_path})
  require('plugin_specification')
  vim.cmd 'autocmd User PackerComplete ++once lua require("my_config")'
  require('packer').sync()
else
  require('my_config')
end


Bootstrapping packer + plugins in a shell script

#!/usr/bin/env sh

install_packer() {
  PACKER_DIRECTORY="${XDG_DATA_HOME:-$HOME/.local/share}/nvim/site/pack/packer/start/packer.nvim"

  if ! [ -d "$PACKER_DIRECTORY" ]; then
    git clone "https://github.com/wbthomason/packer.nvim" "$PACKER_DIRECTORY"
  fi
}

bootstrap_plugins() {
  nvim -u NONE \
    +'autocmd User PackerComplete quitall' \
    +'lua require("plugin_specification")' \
    +'lua require("packer").sync()'
}

install_packer
bootstrap_plugins

I can open a PR to add these snippets to the README if you find them useful.

I think it may be time to move information like this to a FAQ or wiki; the README is already cumbersome. I agree that #259 provides a reasonable mechanism for this behavior, though.

my script for updating plugins from shell(fish):
fish nvim \ +'autocmd User PackerComplete sleep 100m | write ~/.packer.sync.result | qall' \ +PackerSync cat ~/.packer.sync.result | rg -v 'Press'
(or any better | simpler way?)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

SanchayanMaity picture SanchayanMaity  路  8Comments

ghost picture ghost  路  3Comments

rockerBOO picture rockerBOO  路  4Comments

YaBoiBurner picture YaBoiBurner  路  4Comments

akinsho picture akinsho  路  5Comments