aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjdhao <jdhao@hotmail.com>2022-10-16 10:22:09 +0800
committerjdhao <jdhao@hotmail.com>2022-10-16 10:23:40 +0800
commitd939cc75c61dbd7ac514a1b3edd3722488185c5f (patch)
treeee0a27b04d2abbbf8ead3284d62c59020e013ca9
parent26921309ec003a2f829a6ff4efd152c7725069bf (diff)
refactor: make packer installation a function
-rw-r--r--lua/plugins.lua29
1 files changed, 18 insertions, 11 deletions
diff --git a/lua/plugins.lua b/lua/plugins.lua
index 14e6229..fdf3d2e 100644
--- a/lua/plugins.lua
+++ b/lua/plugins.lua
@@ -4,24 +4,31 @@ local fn = vim.fn
-- The root dir to install all plugins. Plugins are under opt/ or start/ sub-directory.
vim.g.plugin_home = fn.stdpath("data") .. "/site/pack/packer"
--- Where to install packer.nvim -- the package manager (we make it opt)
-local packer_dir = vim.g.plugin_home .. "/opt/packer.nvim"
-
--- Whether this is a fresh install, i.e., packer itself and plugins have not been installed.
-local fresh_install = false
+--- Install packer if it has not been installed.
+--- Return:
+--- true: if this is a fresh install of packer
+--- false: if packer has been installed
+local function packer_ensure_install()
+ -- Where to install packer.nvim -- the package manager (we make it opt)
+ local packer_dir = vim.g.plugin_home .. "/opt/packer.nvim"
+
+ if fn.glob(packer_dir) ~= "" then
+ return false
+ end
--- Auto-install packer in case it hasn't been installed.
-if fn.glob(packer_dir) == "" then
- fresh_install = true
+ -- Auto-install packer in case it hasn't been installed.
+ vim.api.nvim_echo({ { "Installing packer.nvim", "Type" } }, true, {})
- -- Now we need to install packer.nvim first.
local packer_repo = "https://github.com/wbthomason/packer.nvim"
local install_cmd = string.format("!git clone --depth=1 %s %s", packer_repo, packer_dir)
-
- vim.api.nvim_echo({ { "Installing packer.nvim", "Type" } }, true, {})
vim.cmd(install_cmd)
+
+ return true
end
+
+local fresh_install = packer_ensure_install()
+
-- Load packer.nvim
vim.cmd("packadd packer.nvim")