Compare commits
2 Commits
c42f1f0370
...
01229cc7b0
Author | SHA1 | Date | |
---|---|---|---|
01229cc7b0 | |||
7ff5a6a634 |
44
nvim/.config/nvim/lua/lupan/cd.lua
Normal file
44
nvim/.config/nvim/lua/lupan/cd.lua
Normal file
@ -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" }, "<CR>", 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
|
@ -37,6 +37,14 @@ key('n', '<leader>fF', function()
|
|||||||
require('telescope.builtin').find_files { hidden = true }
|
require('telescope.builtin').find_files { hidden = true }
|
||||||
end, { desc = '[F]ind [F]iles (with hidden)' })
|
end, { desc = '[F]ind [F]iles (with hidden)' })
|
||||||
|
|
||||||
|
key('n', '<leader>td', function()
|
||||||
|
require('lupan.cd').tab_change_dir()
|
||||||
|
end, { desc = '[T]ab change [d]irectory' })
|
||||||
|
|
||||||
|
key('n', '<leader>tD', function()
|
||||||
|
require('lupan.cd').tab_change_dir_newtab()
|
||||||
|
end, { desc = '[T]ab change [D]irectory (new tab)' })
|
||||||
|
|
||||||
-- Diagnostic keymaps
|
-- Diagnostic keymaps
|
||||||
key('n', '[d', vim.diagnostic.goto_prev, { desc = 'Go to previous diagnostic message' })
|
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' })
|
key('n', ']d', vim.diagnostic.goto_next, { desc = 'Go to next diagnostic message' })
|
||||||
@ -126,3 +134,13 @@ for i = 1, 9, 1 do
|
|||||||
require("harpoon.term").gotoTerminal(i)
|
require("harpoon.term").gotoTerminal(i)
|
||||||
end, { desc = '[H]arpoon nav_file [' .. i .. ']' })
|
end, { desc = '[H]arpoon nav_file [' .. i .. ']' })
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- colors
|
||||||
|
|
||||||
|
key('n', '<F6>', function()
|
||||||
|
if vim.o.background == "dark" then
|
||||||
|
vim.o.background = "light"
|
||||||
|
else
|
||||||
|
vim.o.background = "dark"
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user