sessions and nvim tree

This commit is contained in:
RingOfStorms (Joshua Bell) 2024-05-01 18:11:18 -05:00
parent b542af2f39
commit 78f04bda73
12 changed files with 239 additions and 12 deletions

51
flake.lock generated
View file

@ -257,6 +257,38 @@
"type": "github"
}
},
"nvim_plugin-nvim-tree/nvim-tree.lua": {
"flake": false,
"locked": {
"lastModified": 1714440771,
"narHash": "sha256-yLWb3aKsab3Cqbp3RgP0maiLOQWtxbUdnkLy7sQygx0=",
"owner": "nvim-tree",
"repo": "nvim-tree.lua",
"rev": "347e1eb35264677f66a79466bb5e3d111968e12c",
"type": "github"
},
"original": {
"owner": "nvim-tree",
"repo": "nvim-tree.lua",
"type": "github"
}
},
"nvim_plugin-nvim-tree/nvim-web-devicons": {
"flake": false,
"locked": {
"lastModified": 1714371374,
"narHash": "sha256-gc+8GgFSM87dbcYUW8d9If3qY80xJMmy48vnVezNLPk=",
"owner": "nvim-tree",
"repo": "nvim-web-devicons",
"rev": "794bba734ec95eaff9bb82fbd112473be2087283",
"type": "github"
},
"original": {
"owner": "nvim-tree",
"repo": "nvim-web-devicons",
"type": "github"
}
},
"nvim_plugin-preservim/nerdcommenter": {
"flake": false,
"locked": {
@ -289,6 +321,22 @@
"type": "github"
}
},
"nvim_plugin-rmagatti/auto-session": {
"flake": false,
"locked": {
"lastModified": 1713075135,
"narHash": "sha256-wu/utBYr4o4BenybAumDxBTERBkRkcR1QzlfmnVbOTQ=",
"owner": "rmagatti",
"repo": "auto-session",
"rev": "9e0a169b6fce8791278abbd110717b921afe634d",
"type": "github"
},
"original": {
"owner": "rmagatti",
"repo": "auto-session",
"type": "github"
}
},
"nvim_plugin-windwp/nvim-ts-autotag": {
"flake": false,
"locked": {
@ -323,8 +371,11 @@
"nvim_plugin-nvim-telescope/telescope-fzf-native.nvim": "nvim_plugin-nvim-telescope/telescope-fzf-native.nvim",
"nvim_plugin-nvim-telescope/telescope-ui-select.nvim": "nvim_plugin-nvim-telescope/telescope-ui-select.nvim",
"nvim_plugin-nvim-telescope/telescope.nvim": "nvim_plugin-nvim-telescope/telescope.nvim",
"nvim_plugin-nvim-tree/nvim-tree.lua": "nvim_plugin-nvim-tree/nvim-tree.lua",
"nvim_plugin-nvim-tree/nvim-web-devicons": "nvim_plugin-nvim-tree/nvim-web-devicons",
"nvim_plugin-preservim/nerdcommenter": "nvim_plugin-preservim/nerdcommenter",
"nvim_plugin-rcarriga/nvim-notify": "nvim_plugin-rcarriga/nvim-notify",
"nvim_plugin-rmagatti/auto-session": "nvim_plugin-rmagatti/auto-session",
"nvim_plugin-windwp/nvim-ts-autotag": "nvim_plugin-windwp/nvim-ts-autotag"
}
},

View file

@ -75,10 +75,18 @@
url = "github:windwp/nvim-ts-autotag";
flake = false;
};
# "nvim_plugin-nvim-treesitter/nvim-treesitter" = {
# url = "github:nvim-treesitter/nvim-treesitter";
# flake = false;
# };
"nvim_plugin-rmagatti/auto-session" = {
url = "github:rmagatti/auto-session";
flake = false;
};
"nvim_plugin-nvim-tree/nvim-web-devicons" = {
url = "github:nvim-tree/nvim-web-devicons";
flake = false;
};
"nvim_plugin-nvim-tree/nvim-tree.lua" = {
url = "github:nvim-tree/nvim-tree.lua";
flake = false;
};
};
outputs = { self, nixpkgs, flake-utils, ... } @ inputs:

View file

@ -4,7 +4,6 @@ if NIX then
-- However this pollutes the path, it could be limited to just init files but this approach here one level deep is adequate for my own needs
package.path = package.path .. ";" .. NIX.storePath .. "/lua/?.lua"
package.path = package.path .. ";" .. NIX.storePath .. "/lua/?/init.lua"
print(vim.inspect(NIX))
end
U = require("util") -- NOTE global U[til]

View file

@ -23,13 +23,6 @@ U.keymaps({
{ "<leader>Q", "<nop>", mode = nvx }, -- don't do normal Q quit
{ "<leader>a", "<esc>ggVG", desc = "Select all", mode = nvx },
{ "Q", "<cmd>qa<CR>", desc = "Quit all", mode = nvx },
-- {
-- "<leader>QQ",
-- -- TODO REVISIT is this session stuff still relevant?
-- "<cmd>NvimTreeClose<cr><cmd>SessionDelete<cr><cmd>qa<CR>",
-- desc = "Quit all, no session saved",
-- mode = nvx,
-- },
{ "<leader>y", '"+y', desc = "Copy to system clipboard", mode = nvx },
{ "<leader>p", '"+p', desc = "Paste from system clipboard", mode = nvx },
{ "<esc>", "<cmd>nohlsearch<CR><esc>", desc = "Clear search on escape" },

View file

@ -0,0 +1,157 @@
return {
"nvim-tree/nvim-tree.lua",
lazy = false,
dependencies = {
"nvim-tree/nvim-web-devicons",
},
opts = function()
return {
sort = {
sorter = "case_sensitive",
},
view = {
-- width = getWidth(),
float = {
enable = true,
open_win_config = function()
local cols = vim.api.nvim_get_option("columns")
local rows = vim.api.nvim_get_option("lines")
local width = math.floor(cols / 2)
local height = math.floor(rows / 1.2)
return {
relative = "editor",
row = math.floor(rows / 10),
col = math.floor(cols / 4),
width = width,
height = height,
border = "rounded",
}
end,
},
},
renderer = {
group_empty = true,
indent_width = 3,
icons = {
glyphs = {
git = {
unstaged = "",
},
},
},
},
filters = {
dotfiles = false,
git_ignored = false,
exclude = { ".DS_Store" },
},
actions = {
open_file = {
quit_on_open = true,
window_picker = {
enable = false,
},
},
},
on_attach = function(bufnr)
-- https://github.com/nvim-tree/nvim-tree.lua/wiki/Recipes#modify-you-on_attach-function-to-have-ability-to-operate-multiple-files-at-once
local api = require("nvim-tree.api")
local opts = function(desc)
return { desc = "nvim-tree: " .. desc, buffer = bufnr, noremap = true, silent = true, nowait = true }
end
-- mark operation
local mark_move_j = function()
api.marks.toggle()
vim.cmd("norm j")
end
local mark_move_k = function()
api.marks.toggle()
vim.cmd("norm k")
end
-- marked files operation
local mark_remove = function()
local marks = api.marks.list()
if #marks == 0 then
table.insert(marks, api.tree.get_node_under_cursor())
end
for _, node in ipairs(marks) do
api.fs.remove(node)
end
api.marks.clear()
api.tree.reload()
end
local mark_copy = function()
local marks = api.marks.list()
if #marks == 0 then
table.insert(marks, api.tree.get_node_under_cursor())
end
for _, node in pairs(marks) do
api.fs.copy.node(node)
end
api.marks.clear()
api.tree.reload()
end
local mark_cut = function()
local marks = api.marks.list()
if #marks == 0 then
table.insert(marks, api.tree.get_node_under_cursor())
end
for _, node in pairs(marks) do
api.fs.cut(node)
end
api.marks.clear()
api.tree.reload()
end
local mark_move_to_cursor = function()
local marks = api.marks.list()
if #marks == 0 then
table.insert(marks, api.tree.get_node_under_cursor())
end
for _, node in pairs(marks) do
api.fs.cut(node)
end
api.marks.clear()
api.fs.paste()
api.tree.reload()
end
vim.keymap.set("n", "J", mark_move_j, opts("Toggle Bookmark Down"))
vim.keymap.set("n", "K", mark_move_k, opts("Toggle Bookmark Up"))
vim.keymap.set("n", "x", mark_cut, opts("Cut File(s)"))
vim.keymap.set("n", "d", mark_remove, opts("Remove File(s)"))
vim.keymap.set("n", "y", mark_copy, opts("Copy File(s)"))
vim.keymap.set("n", "<leader>mv", mark_move_to_cursor, opts("Move Bookmarked"))
vim.keymap.set("n", "M", api.marks.clear, opts("Clear Bookmarks"))
-- https://github.com/nvim-tree/nvim-tree.lua/wiki/Recipes#refactoring-of-on_attach-generated-code
vim.keymap.set("n", "q", api.tree.close, opts("Close"))
vim.keymap.set("n", "<esc>", api.tree.close, opts("Close"))
vim.keymap.set("n", "<leader>o", api.tree.close, opts("Close"))
vim.keymap.set("n", "<CR>", api.node.open.edit, opts("Open"))
vim.keymap.set("n", "l", api.node.open.edit, opts("Open"))
vim.keymap.set("n", "h", api.node.navigate.parent_close, opts("Close Directory"))
vim.keymap.set("n", "r", api.fs.rename, opts("Rename"))
vim.keymap.set("n", "a", api.fs.create, opts("Create"))
vim.keymap.set("n", "p", api.fs.paste, opts("Paste"))
vim.keymap.set("n", "R", api.tree.reload, opts("Refresh"))
vim.keymap.set("n", "m", api.marks.toggle, opts("Toggle Bookmark"))
vim.keymap.set("n", "<leader>c", api.fs.copy.absolute_path, opts("Copy Path to Clipboard"))
vim.keymap.set("n", "h", api.node.navigate.parent_close, opts("Close Directory"))
vim.keymap.set("n", "?", api.tree.toggle_help, opts("Help"))
end,
}
end,
keys = {
{ "<leader>e", "<cmd>NvimTreeToggle<cr>", desc = "Open file browser" },
{ "<leader>o", "<cmd>NvimTreeFindFile<cr>", desc = "Open file browser at current buffer" },
},
}

19
lua/plugins/session.lua Normal file
View file

@ -0,0 +1,19 @@
return {
"rmagatti/auto-session",
lazy = false,
init = function()
vim.o.sessionoptions = "blank,buffers,curdir,folds,tabpages,winsize,winpos,terminal,localoptions"
end,
opts = {
auto_session_use_git_branch = true,
auto_session_suppress_dirs = { "~/", "sessions", "~/Downloads", "/" },
post_cwd_changed_hook = function()
U.safeRequire("lualine", function(ll)
ll.refresh() -- refresh lualine so the new session name is displayed in the status bar
end)
end,
},
config = function(_, opts)
require("auto-session").setup(opts)
end,
}