setup project manager

This commit is contained in:
andrzej 2024-05-06 23:01:53 +02:00
parent 4ac106cdb0
commit 808c59f8d7
5 changed files with 77 additions and 10 deletions

View File

@ -1,6 +1,7 @@
vim.g.mapleader = " "
vim.g.maplocalleader = " "
vim.g.have_nerd_font = true
require("project_dotfiles_autocommands")
require("options.default")
require("lazy_bootstrap")
require("lazy").setup({ { import = "plugins" } })

View File

@ -0,0 +1,21 @@
return {
"coffebar/neovim-project",
opts = {
projects = { -- define project roots
"~/projects/*",
"~/.config/*",
"~/dev/*",
},
},
init = function()
-- enable saving the state of plugins in the session
vim.opt.sessionoptions:append("globals") -- save global variables that start with an uppercase letter and contain at least one lowercase letter.
end,
dependencies = {
{ "nvim-lua/plenary.nvim" },
{ "nvim-telescope/telescope.nvim", tag = "0.1.4" },
{ "Shatur/neovim-session-manager" },
},
lazy = false,
priority = 100,
}

View File

@ -1,9 +0,0 @@
return {
"rmagatti/auto-session",
config = function()
require("auto-session").setup({
log_level = "error",
auto_session_suppress_dirs = { "~/", "~/Projects", "~/Downloads", "/" },
})
end,
}

View File

@ -151,7 +151,7 @@ return { -- Fuzzy Finder (files, lsp, etc)
vim.keymap.set(
"n",
"<leader>sp",
"<cmd>lua require'telescope'.extensions.project.project{}<CR>",
"<cmd>:Telescope neovim-project discover<CR>",
{ desc = "[S]earch [P]rojects", noremap = true, silent = true }
)
-- Slightly advanced example of overriding default behavior and theme

View File

@ -0,0 +1,54 @@
local augroup = vim.api.nvim_create_augroup("user_cmds", { clear = true })
local function update_git_env_for_dotfiles()
-- Auto change ENV variables to enable
-- bare git repository for dotfiles after
-- loading saved session
local home = vim.fn.expand("~")
local git_dir = home .. "/dotfiles"
if vim.env.GIT_DIR ~= nil and vim.env.GIT_DIR ~= git_dir then
return
end
-- check dotfiles dir exists on current machine
if vim.fn.isdirectory(git_dir) ~= 1 then
vim.env.GIT_DIR = nil
vim.env.GIT_WORK_TREE = nil
return
end
-- check if the current working directory should belong to dotfiles
local cwd = vim.loop.cwd()
if vim.startswith(cwd, home .. "/.config/") or cwd == home or cwd == home .. "/.local/bin" then
if vim.env.GIT_DIR == nil then
-- export git location into ENV
vim.env.GIT_DIR = git_dir
vim.env.GIT_WORK_TREE = home
end
else
if vim.env.GIT_DIR == git_dir then
-- unset variables
vim.env.GIT_DIR = nil
vim.env.GIT_WORK_TREE = nil
end
end
end
vim.api.nvim_create_autocmd("DirChanged", {
pattern = { "*" },
group = augroup,
desc = "Update git env for dotfiles after changing directory",
callback = function()
update_git_env_for_dotfiles()
end,
})
vim.api.nvim_create_autocmd("User", {
pattern = { "SessionLoadPost" },
group = augroup,
desc = "Update git env for dotfiles after loading session",
callback = function()
update_git_env_for_dotfiles()
end,
})