-- Download packer.
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
		print('Download packer...')
		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

-- Bootstrap packer.
local packer_bootstrap = ensure_packer()

-- Chek packer.
local status, packer = pcall(require, 'packer')
if (not status) then
	print('Oops. Packer is not installed!')
	return
end

-- Init packer.
packer.init({
	display = {
		open_fn = function()
			return require('packer.util').float({ border = 'single' })
		end
	}
})

-- Plugins.
local plugins = require('axp.plugins')

-- Startup packer.
packer.startup(function(use)
	use 'wbthomason/packer.nvim'

	-- Use pludins.
	for _, plugin in ipairs(plugins.list) do
		use(plugin)
	end

	-- Automatically set up your configuration after cloning packer.nvim
	-- Put this at the end after all plugins
	if packer_bootstrap then
		print('Packer sync...')
		require('packer').sync()
	end
end)

-- Init plugins.
plugins.init()
