Compare commits
2 Commits
01229cc7b0
...
c42f1f0370
Author | SHA1 | Date | |
---|---|---|---|
c42f1f0370 | |||
b8e5ff313f |
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 = {}
|
||||
|
||||
function M.tcd(dir)
|
||||
vim.cmd('tcd ' .. dir)
|
||||
end
|
||||
|
||||
function M.tabnew_tcd(dir)
|
||||
vim.cmd('tabnew ' .. dir)
|
||||
vim.cmd('tcd ' .. dir)
|
||||
end
|
||||
|
||||
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 M.tcd
|
||||
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
|
||||
|
||||
return M
|
@ -37,6 +37,15 @@ key('n', '<leader>fF', function()
|
||||
require('telescope.builtin').find_files { hidden = true }
|
||||
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()
|
||||
local cd = require('lupan.cd')
|
||||
cd.tab_change_dir({ action = cd.tabnew_tcd, prompt_title = "Tab change directory (new tab)" })
|
||||
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' })
|
||||
@ -126,3 +135,13 @@ for i = 1, 9, 1 do
|
||||
require("harpoon.term").gotoTerminal(i)
|
||||
end, { desc = '[H]arpoon nav_file [' .. i .. ']' })
|
||||
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