jvgrootveld/telescope-zoxide

github github
fuzzy-finder plugin
star 42
stars
alert-circle 0
open issues
users 1
subscribers
git-branch 3
forks
CREATED

2021-03-27

UPDATED

4 days ago

packer

require('packer').startup(function()
  use 'jvgrootveld/telescope-zoxide'
end)

paq

require "paq" { 
  'jvgrootveld/telescope-zoxide'
}

Telescope Zoxide

An extension for telescope.nvim that allows you operate zoxide within Neovim.

Requirements

zoxide is required to use this plugin.

Installation

Plug 'nvim-lua/popup.nvim'
Plug 'nvim-lua/plenary.nvim'
Plug 'nvim-telescope/telescope.nvim'
Plug 'jvgrootveld/telescope-zoxide'

Setup

You can setup the extension by adding the following to your config:

require'telescope'.load_extension('zoxide')

Available functions:

List

With Telescope command

:Telescope zoxide list

In Lua

require'telescope'.extensions.zoxide.list{}

Overridable config

You can add, extend and update Telescope Zoxide config by calling the setup function after loading the plugin.

You can add new mappings and extend default mappings. (Note: The mapping with the key 'default' is the mapping invoked on pressing <cr>). Every keymapping must have an action function and supports the optional functions before_action and after_action.

Tip: If the action is a telescope picker, you should also set keepinsert = true to open it in insert mode. Else you can't directly type into the next telescope picker.

All action functions are called with the current selection object as parameter which contains the selected path and Zoxide score.

Tip: Make use of the supplied z_utils.create_basic_command helper function to easily invoke a vim command for the selected path.

Example setup

local z_utils = require("telescope._extensions.zoxide.utils")

require("telescope._extensions.zoxide.config").setup({
  prompt_title = "[ Walking on the shoulders of TJ ]",
  mappings = {
    default = {
      after_action = function(selection)
        print("Update to (" .. selection.z_score .. ") " .. selection.path)
      end
    },
    ["<C-s>"] = {
      before_action = function(selection) print("before C-s") end,
      action = function(selection)
        vim.cmd("edit " .. selection.path)
      end
    },
    ["<C-q>"] = { action = z_utils.create_basic_command("split") },
  }
})

Default config

{
  prompt_title = "[ Zoxide List ]",

  -- Zoxide list command with score
  list_command = "zoxide query -ls",
  mappings = {
    default = {
      action = function(selection)
        vim.cmd("cd " .. selection.path)
      end,
      after_action = function(selection)
        print("Directory changed to " .. selection.path)
      end
    },
    ["<C-s>"] = { action = z_utils.create_basic_command("split") },
    ["<C-v>"] = { action = z_utils.create_basic_command("vsplit") },
    ["<C-e>"] = { action = z_utils.create_basic_command("edit") },
    ["<C-b>"] = {
      keepinsert = true,
      action = function(selection)
        builtin.file_browser({ cwd = selection.path })
      end
    },
    ["<C-f>"] = {
      keepinsert = true,
      action = function(selection)
        builtin.find_files({ cwd = selection.path })
      end
    }
  }
}

Example config:

vim.api.nvim_set_keymap(
    "n",
    "<leader>cd",
    ":lua require'telescope'.extensions.zoxide.list{}<CR>",
    {noremap = true, silent = true}
)

Default mappings:

Action Description Command executed
<CR> Change current directory to selection cd <path>
<C-s> Open selection in a split split <path>
<C-v> Open selection in a vertical split vsplit <path>
<C-e> Open selection in current window edit <path>
<C-b> Open selection in telescope's builtin.file_browser builtin.file_browser({ cwd = selection.path })
<C-f> Open selection in telescope's builtin.find_files builtin.find_files({ cwd = selection.path })