Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for fzf-lua #20

Open
p5quared opened this issue Jul 26, 2024 · 3 comments
Open

Support for fzf-lua #20

p5quared opened this issue Jul 26, 2024 · 3 comments
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@p5quared
Copy link
Owner

#18 Some people would rather use fzf-lua as their picker.

@p5quared p5quared added enhancement New feature or request good first issue Good for newcomers labels Jul 26, 2024
@p5quared p5quared added help wanted Extra attention is needed and removed good first issue Good for newcomers labels Jul 29, 2024
@ducktordanny
Copy link
Contributor

ducktordanny commented Jul 29, 2024

I'm not sure how to handle this, because if I use only telescope I might not want to have fzf-lua as a dependency, idk if there are ways to handle this?

Anyway, I was able to create a similar picker in fzf-lua to what we have for telescope, it's kinda simple to do it:

return {
  "ibhagwan/fzf-lua",
  dependencies = { "nvim-tree/nvim-web-devicons" },
  config = function()
    local fzf_lua = require "fzf-lua"
    local apple_music = require "apple-music"
    fzf_lua.setup {}
    local custom_list = function()
      local track_list = apple_music.get_tracks()
      -- print(vim.inspect(track_list))
      fzf_lua.fzf_exec(track_list, {
        prompt = "Tracks with FZF ",
        previewer = false,
        actions = {
          ["default"] = function(selected)
            -- print(vim.inspect(selected)) -- returns track in table
            apple_music.play_track(selected[1])
          end,
        },
      })
    end
    vim.keymap.set("n", "<leader>fa", custom_list)
  end,
}
Screen.Recording.2024-07-29.at.23.14.51.mp4

I just installed it with lazy.nvim as I don't really use fzf-lua and created a custom picker that looks like this (you can see the current track changing at the top) ☝️. I thought I would leave this here for future reference/help.

@p5quared
Copy link
Owner Author

I was hoping that we could put the dependent require() inside of the functions and we wouldn't need them unless we called xyz_with_fzf(). Then when someone installs they specify one of the necessary dependencies.

I am assuming that if a function with a require never gets called then we don't really need whatever is required by that function. I'm not really familiar with Lua though and haven't tried this at all.

@ducktordanny
Copy link
Contributor

We can also do something like package.loaded["telescope"] and package.loaded["fzf-lua"], and it returns nil if the package is not loaded. I could imagine using this as a condition inside the picker functions, and just making sure we have the right dependencies for using require.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants