diff --git a/nvim/.config/nvim/lua/lupan/remap.lua b/nvim/.config/nvim/lua/lupan/remap.lua index 3b0f015..1dfdb7f 100644 --- a/nvim/.config/nvim/lua/lupan/remap.lua +++ b/nvim/.config/nvim/lua/lupan/remap.lua @@ -37,6 +37,14 @@ key('n', 'fF', function() require('telescope.builtin').find_files { hidden = true } end, { desc = '[F]ind [F]iles (with hidden)' }) +key('n', 'td', function() + require('lupan.ui').tab_change_dir() +end, { desc = '[T]ab change [d]irectory' }) + +key('n', 'tD', function() + require('lupan.ui').tab_change_dir_newtab() +end, { desc = '[T]ab change [D]irectory (new tab)' }) + -- Diagnostic keymaps key('n', '[d', vim.diagnostic.goto_prev, { desc = 'Go to previous diagnostic message' }) key('n', ']d', vim.diagnostic.goto_next, { desc = 'Go to next diagnostic message' }) diff --git a/nvim/.config/nvim/lua/lupan/ui.lua b/nvim/.config/nvim/lua/lupan/ui.lua new file mode 100644 index 0000000..f068b5c --- /dev/null +++ b/nvim/.config/nvim/lua/lupan/ui.lua @@ -0,0 +1,44 @@ +local actions = require "telescope.actions" +local action_state = require "telescope.actions.state" +local finders = require "telescope.finders" +local pickers = require "telescope.pickers" +local sorters = require "telescope.sorters" +local themes = require "telescope.themes" + +local M = {} + +local function enter(prompt_bufnr, action) + local selected = action_state.get_selected_entry() + actions.close(prompt_bufnr) + action(selected[1]) +end + +function M.tab_change_dir(opts) + opts = opts or {} + local action = opts.action or vim.cmd.tc + local prompt_title = opts.prompt_title or "Tab change directory" + local cmd = { 'find', os.getenv('HOME'), '-maxdepth', '5', '-type', 'd', '-not', '-path', '*/.git*' } + local dropdown = themes.get_dropdown(); + local picker_opts = { + prompt_title = prompt_title, + finder = finders.new_oneshot_job(cmd, {}), + sorter = sorters.get_fuzzy_file({}), + attach_mappings = function(_, map) + map({ "i", "n" }, "", function(prompt_bufnr) enter(prompt_bufnr, action) end) + return true + end + } + local change_dir = pickers.new(dropdown, picker_opts) + change_dir:find() +end + +local function tabnew_tcd(dir) + vim.cmd.tabnew(dir) + vim.cmd.tc(dir) +end + +function M.tab_change_dir_newtab() + M.tab_change_dir({ action = tabnew_tcd, prompt_title = "Tab change directory (new tab)" }) +end + +return M