p5quared/apple-music.nvim

Support for `fzf-lua`

Opened this issue · 3 comments

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

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.

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.

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.