television and zoxide integration
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
-- Zoxide integration for Neovim
|
||||
-- Allows you to use zoxide's smart directory jumping within Neovim
|
||||
|
||||
-- Install telescope-zoxide plugin
|
||||
local gh = function(repo)
|
||||
return 'https://github.com/' .. repo
|
||||
end
|
||||
|
||||
vim.pack.add { gh 'jvgrootveld/telescope-zoxide' }
|
||||
|
||||
-- Configure telescope-zoxide
|
||||
require('telescope').load_extension 'zoxide'
|
||||
|
||||
-- Keymaps for zoxide
|
||||
vim.keymap.set('n', '<leader>cd', function()
|
||||
require('telescope').extensions.zoxide.list()
|
||||
end, { desc = '[C]hange [D]irectory with zoxide' })
|
||||
|
||||
-- Optional: Create a command to change directory using zoxide
|
||||
vim.api.nvim_create_user_command('Z', function(opts)
|
||||
local path = opts.args
|
||||
if path == '' then
|
||||
-- If no argument, open telescope picker
|
||||
require('telescope').extensions.zoxide.list()
|
||||
else
|
||||
-- Otherwise, use zoxide to find and change to directory
|
||||
local handle = io.popen('zoxide query -- ' .. vim.fn.shellescape(path))
|
||||
if handle then
|
||||
local result = handle:read '*a'
|
||||
handle:close()
|
||||
result = result:gsub('%s+$', '') -- trim trailing whitespace
|
||||
if result ~= '' then
|
||||
vim.cmd('cd ' .. vim.fn.fnameescape(result))
|
||||
print('Changed directory to: ' .. result)
|
||||
else
|
||||
print('Directory not found in zoxide database')
|
||||
end
|
||||
end
|
||||
end
|
||||
end, { nargs = '*', desc = 'Change directory using zoxide' })
|
||||
|
||||
-- Optional: Create commands similar to zoxide's zi (interactive)
|
||||
vim.api.nvim_create_user_command('Zi', function()
|
||||
require('telescope').extensions.zoxide.list()
|
||||
end, { desc = 'Interactive zoxide directory picker' })
|
||||
|
||||
-- Optional: Add zoxide entries when changing directories in Neovim
|
||||
-- This keeps your zoxide database in sync with Neovim directory changes
|
||||
vim.api.nvim_create_autocmd('DirChanged', {
|
||||
callback = function()
|
||||
local dir = vim.fn.getcwd()
|
||||
vim.fn.system('zoxide add ' .. vim.fn.shellescape(dir))
|
||||
end,
|
||||
desc = 'Add directory to zoxide database when changing directories in Neovim',
|
||||
})
|
||||
Reference in New Issue
Block a user