Skip to content

Commit 07087b6

Browse files
committed
feat(neovim): swap unmaintained workspaces.nvim with project.nvim
1 parent c5ae7b2 commit 07087b6

File tree

7 files changed

+77
-49
lines changed

7 files changed

+77
-49
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ home/.config/coc/extensions/*
1212
home/.local/share/nvim/view/
1313
home/.local/share/nvim/undo/
1414
home/.local/share/nvim/shada/
15-
home/.local/share/nvim/workspaces
1615
home/.local/share/nvim/project_nvim/
1716
home/.local/share/nvim/mason/
1817
home/.local/share/nvim/neo-tree.nvim.log

.gitmodules

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -419,9 +419,6 @@
419419
[submodule "home/.local/share/nvim/site/pack/default/start/nvim-autopairs"]
420420
path = home/.local/share/nvim/site/pack/default/start/nvim-autopairs
421421
url = https://github.com/windwp/nvim-autopairs.git
422-
[submodule "home/.local/share/nvim/site/pack/default/start/workspaces.nvim"]
423-
path = home/.local/share/nvim/site/pack/default/start/workspaces.nvim
424-
url = https://github.com/natecraddock/workspaces.nvim.git
425422
[submodule "home/.local/share/nvim/site/pack/default/start/persistence.nvim"]
426423
path = home/.local/share/nvim/site/pack/default/opt/persistence.nvim
427424
url = https://github.com/folke/persistence.nvim.git
@@ -609,3 +606,6 @@
609606
[submodule "home/.local/share/nvim/site/pack/default/opt/difftastic.nvim"]
610607
path = home/.local/share/nvim/site/pack/default/opt/difftastic.nvim
611608
url = https://github.com/clabby/difftastic.nvim.git
609+
[submodule "home/.local/share/nvim/site/pack/default/start/project.nvim"]
610+
path = home/.local/share/nvim/site/pack/default/start/project.nvim
611+
url = https://github.com/DrKJeff16/project.nvim.git
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
local pickers = require("pickers")
2+
local defer = require("defer")
3+
4+
local function on_attach()
5+
local persistence = require("persistence")
6+
persistence.start()
7+
if vim.uv.fs_stat(require("persistence").current()) ~= nil then
8+
persistence.load()
9+
10+
local wins = vim.api.nvim_list_wins()
11+
for _, w in ipairs(wins) do
12+
-- ex bufname neo-tree filesystem [1]
13+
local bufnr = vim.api.nvim_win_get_buf(w)
14+
local bufname = vim.api.nvim_buf_get_name(bufnr)
15+
if bufname:match("neo%-tree filesystem") ~= nil then
16+
vim.api.nvim_win_close(w, true)
17+
vim.api.nvim_buf_delete(bufnr, { force = true })
18+
vim.cmd.Neotree("show")
19+
break
20+
end
21+
end
22+
else
23+
pickers.project_files()
24+
end
25+
end
26+
27+
require("project").setup({
28+
-- first argument is the workspace name
29+
before_attach = function(target_dir)
30+
local persistence = require("persistence")
31+
if persistence.active() then
32+
local cwd = vim.uv.cwd()
33+
if cwd and vim.fs.normalize(cwd) ~= vim.fs.normalize(target_dir) then
34+
persistence.save()
35+
end
36+
persistence.stop()
37+
end
38+
end,
39+
on_attach = on_attach,
40+
})
41+
42+
vim.api.nvim_create_autocmd({ "VimEnter" }, {
43+
pattern = "*",
44+
group = vim.api.nvim_create_augroup("ProjectVimEnter", {}),
45+
nested = true,
46+
callback = function()
47+
-- dont autoload if nvim start with arg
48+
if vim.fn.argc(-1) > 0 then
49+
return
50+
end
51+
52+
local root, method = require("project").get_project_root()
53+
if not root then
54+
return
55+
end
56+
57+
if vim.fn.fnamemodify(vim.fn.getcwd(), ":p:h") == root then
58+
on_attach()
59+
return
60+
end
61+
62+
require("project.api").set_pwd(root, method)
63+
end,
64+
})
65+
66+
defer.on_postload("telescope", function()
67+
require("telescope").load_extension("projects")
68+
end)
69+
70+
pickers.map(pickers.prefix .. "w", function(telescope)
71+
telescope.extensions.projects.projects()
72+
end, { desc = "projects" })

home/.config/nvim/plugin/telescope.lua

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ defer.on_load("telescope", function()
1212
})
1313

1414
-- Load extensions only after telescope itself is initialized
15-
local extensions = { "fzf", "neoclip", "file_browser", "workspaces", "git_grep" }
15+
local extensions = { "fzf", "neoclip", "file_browser", "git_grep" }
1616
for _, ext in ipairs(extensions) do
1717
telescope.load_extension(ext)
1818
end
@@ -49,9 +49,6 @@ end, { desc = "neoclip" })
4949
pickers.map(prefix .. "t", function(telescope)
5050
telescope.extensions.file_browser.file_browser()
5151
end, { desc = "file_browser" })
52-
pickers.map(prefix .. "w", function(telescope)
53-
telescope.extensions.workspaces.workspaces()
54-
end, { desc = "workspaces" }) -- r for ripgrep
5552

5653
-- git
5754
local git_grep_conditional = function()

home/.config/nvim/plugin/workspaces.lua

Lines changed: 0 additions & 40 deletions
This file was deleted.
Submodule project.nvim added at 5e878c8
Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)