summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGustaf Rydholm <gustaf.rydholm@gmail.com>2022-04-10 19:34:44 +0200
committerGustaf Rydholm <gustaf.rydholm@gmail.com>2022-04-10 19:34:44 +0200
commitfef2c0df450b33fd680f8ba7c824be7c843dcd82 (patch)
tree53d6a0fe319eb0bcd2fca986723460bdfdb6302d
parent38215110f1c1290b5b7ef6401db1c1310a2a94b6 (diff)
refactor(bootstrap): add bootstrap
-rw-r--r--lua/bootstrap.lua28
-rw-r--r--lua/config/packer.lua23
-rw-r--r--lua/install.lua42
3 files changed, 54 insertions, 39 deletions
diff --git a/lua/bootstrap.lua b/lua/bootstrap.lua
new file mode 100644
index 0000000..ea8f95b
--- /dev/null
+++ b/lua/bootstrap.lua
@@ -0,0 +1,28 @@
+-- Bootstrap nvim with essential plugins.
+local fn = vim.fn
+local fmt = string.format
+local execute = vim.api.nvim_command
+
+local function ensure(user, repository)
+ local packer_path = fn.stdpath "data" .. "/site/pack"
+ local ensure_path = fmt("%s/packer/start/%s", packer_path, repository)
+ if fn.empty(fn.glob(ensure_path)) > 0 then
+ PACKER_BOOTSTRAP = execute(
+ fmt(
+ "!git clone --depth 1 https://github.com/%s/%s %s",
+ user,
+ repository,
+ ensure_path
+ )
+ )
+ execute(fmt("packadd %s", repository))
+ end
+end
+
+-- Bootstrap install essential modules if not present
+ensure("wbthomason", "packer.nvim")
+ensure("lewis6991", "impatient.nvim")
+
+-- Enable faster loading with impatient
+require "config.impatient"
+return PACKER_BOOTSTRAP
diff --git a/lua/config/packer.lua b/lua/config/packer.lua
new file mode 100644
index 0000000..9302149
--- /dev/null
+++ b/lua/config/packer.lua
@@ -0,0 +1,23 @@
+local status_ok, packer = pcall(require, "packer")
+if not status_ok then
+ return
+end
+
+-- Autocommand that reloads neovim whenever you save the plugins.lua file
+vim.cmd [[
+ augroup packer_user_config
+ autocmd!
+ autocmd BufWritePost plugins.lua source <afile> | PackerSync
+ augroup end
+]]
+
+-- Have packer use a popup window
+packer.init {
+ display = {
+ open_fn = function()
+ return require("packer.util").float { border = "rounded" }
+ end,
+ },
+}
+
+return packer
diff --git a/lua/install.lua b/lua/install.lua
index b362913..cf0a9c3 100644
--- a/lua/install.lua
+++ b/lua/install.lua
@@ -1,45 +1,9 @@
-- Installs plugins with packer.
-
-local fn = vim.fn
local plugins = require "plugins"
--- Automatically install packer
-local install_path = fn.stdpath "data" .. "/site/pack/packer/start/packer.nvim"
-if fn.empty(fn.glob(install_path)) > 0 then
- PACKER_BOOTSTRAP = fn.system {
- "git",
- "clone",
- "--depth",
- "1",
- "https://github.com/wbthomason/packer.nvim",
- install_path,
- }
- print "Installing packer close and reopen Neovim..."
- vim.cmd [[packadd packer.nvim]]
-end
-
--- Autocommand that reloads neovim whenever you save the plugins.lua file
-vim.cmd [[
- augroup packer_user_config
- autocmd!
- autocmd BufWritePost plugins.lua source <afile> | PackerSync
- augroup end
-]]
-
--- Use a protected call so we don't error out on first use
-local status_ok, packer = pcall(require, "packer")
-if not status_ok then
- return
-end
+PACKER_BOOTSTRAP = require "bootstrap"
--- Have packer use a popup window
-packer.init {
- display = {
- open_fn = function()
- return require("packer.util").float { border = "rounded" }
- end,
- },
-}
+local packer = require "config.packer"
-- Install your plugins here
return packer.startup(function(use)
@@ -50,6 +14,6 @@ return packer.startup(function(use)
-- Automatically set up your configuration after cloning packer.nvim
-- Put this at the end after all plugins
if PACKER_BOOTSTRAP then
- require("packer").sync()
+ packer.sync()
end
end)