-- auto install packer if not installed
local ensure_packer = function()
  local fn = vim.fn
  local install_path = fn.stdpath("data") .. "/site/pack/packer/start/packer.nvim"
  if fn.empty(fn.glob(install_path)) > 0 then
    fn.system({ "git", "clone", "--depth", "1", "https://github.com/wbthomason/packer.nvim", install_path })
    vim.cmd([[packadd packer.nvim]])
    return true
  end
  return false
end
local packer_bootstrap = ensure_packer() -- true if packer was just installed

-- autocommand that reloads neovim and installs/updates/removes plugins
-- when file is saved
vim.cmd([[ 
  augroup packer_user_config
    autocmd!
    autocmd BufWritePost setup.lua source <afile> | PackerSync
  augroup end
]])

-- import packer safely
local status, packer = pcall(require, "packer")
if not status then
  return
end

-- add list of plugins to install
return packer.startup(function(use)
  -- packer can manage itself
  use("wbthomason/packer.nvim")

  -- Your additional plugins go here
  -- Example:
  use("nvim-lua/plenary.nvim") -- lua functions that many plugins use
  use("folke/tokyonight.nvim") -- preferred colorscheme
  use("christoomey/vim-tmux-navigator") -- tmux & split window navigation
  -- ... (list all your plugins as you have in your original configuration)

  -- Ensure packer is installed on first run
  if packer_bootstrap then
    require("packer").sync()
  end
end)

