{ nix2lua }: { configs ? { } , keymaps ? [ { mode = "n"; bind = "nt"; command = "NvimTreeToggle"; } { mode = "n"; bind = "nf"; command = "NvimTreeFindFile"; } ] }: with nix2lua.lib; let vimKeymapSet = { mode, bind, command }: call "vim.keymap.set" [ mode bind command ]; isEmptyVar = name: eq "" (var name); in { nvim-tree-lua = ( [ (pipe [ (require "nvim-tree") (call "setup" [ configs ]) ]) (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" (eq 1 (var "vim.fn.isdirectory(data.file)")) )) (if' (not (and (var "isNoNameBuffer") (var "isDirectory"))) [ return_void ]) # change to the directory (if' (var "isDirectory") [ (call "vim.cmd.cd" [ (var "data.file") ]) ]) # open the tree (pipe [ (require "nvim-tree.api") (call "tree.open" [ ]) ]) ])) (call "vim.api.nvim_create_autocmd" [ [ "VimEnter" ] { callback = var "open_nvim_tree"; } ]) ] ++ (map vimKeymapSet keymaps) ); }