axkirillov / easypick.nvim

A neovim plugin that lets you easily create Telescope pickers from arbitrary console commands
MIT License
392 stars 10 forks source link

Possible to use with Lazy.nvim? #20

Open jondkinney opened 2 months ago

jondkinney commented 2 months ago

I can't figure out the right config to get the plugin to load properly within the context of my AstroNvim setup using the Lazy.nvim plugin manager.

Lazy shows that easypick is loaded, but :Easypick isn't an available user command to run.

Here's the current config I'm trying to use:

return {
  "nvim-telescope/telescope.nvim",
  dependencies = {
    "axkirillov/easypick.nvim",
    lazy = false,
  },
  config = function(plugin, opts)
    local easypick = require "easypick"

    require "astronvim.plugins.configs.telescope"(plugin, opts)
    require("telescope").load_extension "easypick"

    -- only required for the example to work
    local get_default_branch = "git rev-parse --symbolic-full-name refs/remotes/origin/HEAD | sed 's!.*/!!'"
    local base_branch = vim.fn.system(get_default_branch):gsub("\n", "") or "main"

    easypick.setup {
      pickers = {
        -- add your custom pickers here
        -- below you can find some examples of what those can look like

        -- list files inside current folder with default previewer
        {
          -- name for your custom picker, that can be invoked using :Easypick <name> (supports tab completion)
          name = "ls",
          -- the command to execute, output has to be a list of plain text entries
          command = "ls",
          -- specify your custom previwer, or use one of the easypick.previewers
          previewer = easypick.previewers.default(),
        },

        -- diff current branch with base_branch and show files that changed with respective diffs in preview
        {
          name = "changed_files",
          command = "git diff --name-only $(git merge-base HEAD " .. base_branch .. " )",
          previewer = easypick.previewers.branch_diff { base_branch = base_branch },
        },

        -- list files that have conflicts with diffs in preview
        {
          name = "conflicts",
          command = "git diff --name-only --diff-filter=U --relative",
          previewer = easypick.previewers.file_diff(),
        },
      },
    }
  end,
}

Any pointers would be greatly appreciated!

jaydorsey commented 1 month ago
}

end, }

There might be a better way to do this, but adding lazy = false after your last end might work. That's how I have mine setup. There might be a better way to get it to load (trigger or something) but I think that's at least worth a try.

axkirillov commented 1 month ago

Hi John, did you solve this problem? I don't use easypick anymore, but I had no problems with Lazy, when I did @jondkinney

russell-knight commented 1 week ago

I'm having trouble getting this working with Lazy as well. My config is below. I'm able to invoke the EasyPicker command, but any of the options I select (e.g changed_files) just opens Telescope, but doesn't populate it with anything.

return {
    "axkirillov/easypick.nvim",
    dependencies = "nvim-telescope/telescope.nvim",
    config = function()
        local easypick = require("easypick")

        -- required for git pickers
        local get_default_branch = "git rev-parse --symbolic-full-name refs/remotes/origin/HEAD | sed 's!.*/!!'"
        local base_branch = vim.fn.system(get_default_branch) or "main"

        easypick.setup({
            pickers = {
                -- add your custom pickers here
                -- below you can find some examples of what those can look like

                -- list files inside current folder with default previewer
                {
                    -- name for your custom picker, that can be invoked using :Easypick <name> (supports tab completion)
                    name = "ls",
                    -- the command to execute, output has to be a list of plain text entries
                    command = "ls",
                    -- specify your custom previwer, or use one of the easypick.previewers
                    previewer = easypick.previewers.default(),
                },

                -- diff current branch with base_branch and show files that changed with respective diffs in preview
                {
                    name = "changed_files",
                    command = "git diff --name-only $(git merge-base HEAD " .. base_branch .. " )",
                    previewer = easypick.previewers.branch_diff({ base_branch = base_branch }),
                },

                -- list files that have conflicts with diffs in preview
                {
                    name = "conflicts",
                    command = "git diff --name-only --diff-filter=U --relative",
                    previewer = easypick.previewers.file_diff(),
                },
            },
        })
    end,
}
axkirillov commented 1 week ago

Hello. I will paste my full easypick config here.

-- get default branch
local default_branch = vim.fn.system("git rev-parse --symbolic-full-name refs/remotes/origin/HEAD | sed 's!.*/!!'") or
"main"

return {
    'axkirillov/easypick.nvim',
    branch = 'develop',
    dependencies = 'nvim-telescope/telescope.nvim',
    config = function()
        local easypick = require("easypick")
        easypick.setup({
            pickers = {
                {
                    name = "changed files",
                    command = "git diff --name-only $(git merge-base HEAD " .. default_branch .. " )",
                    previewer = easypick.previewers.branch_diff({ base_branch = default_branch })
                },
                {
                    name = "conflicts",
                    command = "git diff --name-only --diff-filter=U --relative",
                    previewer = easypick.previewers.file_diff(),
                },
            }
        })

        local ns = { noremap = true, silent = true }
        vim.keymap.set("n", "<C-p>", ":Easypick<CR>", ns)
    end
}
axkirillov commented 1 week ago

For me it works. The only problem I sometimes have, is that in some repos git rev-parse --symbolic-full-name refs/remotes/origin/HEAD | sed 's!.*/!!' fails with an error message, so, you can check that, and act accordingly @russell-knight

axkirillov commented 1 week ago

Actually, this command works reliably for me git remote show origin | grep 'HEAD branch' | cut -d' ' -f5. I will update the docs with it.

axkirillov commented 1 week ago

@jondkinney easypick is not a telescope extension, so you don't need this line

    require("telescope").load_extension "easypick"
russell-knight commented 1 week ago

Hi @axkirillov thanks for your reply. I've tried both your original suggestion and replacing the git rev... line with git remote show origin | grep 'HEAD branch' | cut -d' ' -f5 but I'm still facing the same issue. It's worth mentioning that I get the same outcome when I run any of the custom pickers I have set up (ls, changed_files etc.).

Is there any more information I can provide to help debug this? I am on Windows using Neovim v0.10.2.

axkirillov commented 1 week ago

@russell-knight what happens, when you do :! git remote show origin | grep 'HEAD branch' | cut -d' ' -f5 ?