summary refs log tree commit diff
path: root/.vim
diff options
context:
space:
mode:
authorRobert Günzler <r@gnzler.io>2022-05-18 16:24:47 +0200
committerRobert Günzler <r@gnzler.io>2022-05-27 13:16:16 +0200
commitc0b5557c3aaf26e7444e2bc0d11256d2ac040e5f (patch)
treefee43decec23cc800ef742f11963b0138e977f25 /.vim
parenta3d40096b0072e3192f54e0814e917c83d3e2a01 (diff)
vim: properly setup packer on fresh system
Diffstat (limited to '.vim')
-rw-r--r--.vim/lua/plugins.lua32
1 files changed, 21 insertions, 11 deletions
diff --git a/.vim/lua/plugins.lua b/.vim/lua/plugins.lua
index 3f109fe..86ae9f5 100644
--- a/.vim/lua/plugins.lua
+++ b/.vim/lua/plugins.lua
@@ -1,21 +1,24 @@
 -- vim: fdm=marker fdl=0
 ---@diagnostic disable: undefined-global
 
--- load by calling `lua require('plugins')` from your init.vim
+-- load by calling `lua require('plugins')` from init.vim
+
 local g = vim.g
 local augroup = vim.api.nvim_create_augroup
 local autocmd = vim.api.nvim_create_autocmd
 
 -- force packer into a system directory {{{
+if not vim.fn.filewritable(vim.fn.stdpath('cache')) == 2 then
+  return
+end
+
 -- local datadir = vim.fn.stdpath('data_dirs')[1]
 local datadir = vim.fn.stdpath('data')
-local install_path = require('packer.util').join_paths(datadir, '/site/pack/packer/start/packer.nvim')
+local install_path = datadir .. '/site/pack/packer/start/packer.nvim'
 if vim.fn.empty(vim.fn.glob(install_path)) > 0 then
-  vim.fn.system({ 'git', 'clone', 'https://github.com/wbthomason/packer.nvim', install_path })
-  vim.api.nvim_command 'packadd packer.nvim'
-end
-if not vim.fn.filewritable(vim.fn.stdpath('cache')) == 2 then
-  return
+  vim.notify('Installing packer.nvim...')
+  vim.fn.system({ 'git', 'clone', '--depth=1', 'https://github.com/wbthomason/packer.nvim', install_path })
+  vim.api.nvim_command([[packadd packer.nvim]])
 end
 -- }}}
 
@@ -41,7 +44,10 @@ local function disable_distribution_plugins() -- {{{
 end -- }}}
 
 -- we change the packer.compile_path below, so we need to require it here...
-require('packer_compiled')
+local compilepath = vim.fn.stdpath('config') .. '/lua/packer_compiled.lua'
+if not (vim.fn.empty(vim.fn.glob(compilepath)) > 0) then
+  require('packer_compiled')
+end
 -- auto-compile on save -- {{{
 do
   vim.api.nvim_create_user_command(
@@ -65,7 +71,7 @@ do
   })
 end -- }}}
 
-return require('packer').startup({function()
+require('packer').startup({function()
   -- disable built-in plugins
   disable_distribution_plugins()
 
@@ -1205,8 +1211,7 @@ return require('packer').startup({function()
     end}
 end,
 config = {
-  package_root = require('packer.util').join_paths(datadir, 'site/pack'),
-  compile_path = require('packer.util').join_paths(vim.fn.stdpath('config'), 'lua/packer_compiled.lua'),
+  compile_path = compilepath,
   git = {
     subcommands = {
       update = 'pull --ff-only --progress --rebase=true',
@@ -1217,3 +1222,8 @@ config = {
     threshold = 1,
   }
 }})
+
+-- run sync() if compilepath doesn't exist (this usually means first start)
+if vim.fn.empty(vim.fn.glob(compilepath)) > 0 then
+  require('packer').sync()
+end