This repository has been archived on 2024-05-17. You can view files and clone it, but cannot push or open issues or pull requests.
neovim/modules/nvim-tree-lua.nix

51 lines
1.2 KiB
Nix
Raw Normal View History

2024-04-20 23:05:33 +03:00
{ nix2lua, vim, ... }:
2024-04-17 19:35:34 +03:00
{ configs ? { }
, keymaps ? [
{ mode = "n"; bind = "<leader>nt"; command = "<CMD>NvimTreeToggle<CR>"; }
{ mode = "n"; bind = "<leader>nf"; command = "<CMD>NvimTreeFindFile<CR>"; }
]
}:
with nix2lua.lib;
2024-04-20 23:05:33 +03:00
let isEmptyVar = name: eq "" (var name); in
2024-04-17 19:35:34 +03:00
{
2024-04-18 01:26:40 +03:00
nvim-web-devicons = true;
2024-04-17 19:35:34 +03:00
nvim-tree-lua = (
[
2024-04-20 23:05:33 +03:00
(pipe1 (require "nvim-tree") (call "setup" configs))
2024-04-17 19:35:34 +03:00
(local (func "open_nvim_tree" [ "data" ] [
# buffer is a [No Name]
(local (set "isNoNameBuffer"
(and
(isEmptyVar "data.file")
(isEmptyVar "vim.bo[data.buf].buftype")
)
))
# buffer is a directory
(local (set "isDirectory"
2024-04-20 23:05:33 +03:00
(eq 1 (vim.fn.isdirectory "data.file"))
2024-04-17 19:35:34 +03:00
))
2024-04-20 23:05:33 +03:00
(if' (not (and (var "isNoNameBuffer") (var "isDirectory")))
2024-04-17 19:35:34 +03:00
return_void
2024-04-20 23:05:33 +03:00
)
2024-04-17 19:35:34 +03:00
# change to the directory
2024-04-20 23:05:33 +03:00
(if' (var "isDirectory")
(vim.cmd.cd "data.file")
)
2024-04-17 19:35:34 +03:00
# open the tree
2024-04-20 23:05:33 +03:00
(pipe1 (require "nvim-tree.api") (call0 "tree.open"))
2024-04-17 19:35:34 +03:00
]))
2024-04-20 23:05:33 +03:00
(vim.api.nvim_create_autocmd [ "VimEnter" ] { callback = var "open_nvim_tree"; })
2024-04-17 19:35:34 +03:00
]
2024-04-20 23:05:33 +03:00
++ (map vim.keymap.set keymaps)
2024-04-17 19:35:34 +03:00
);
}