Skip to content
dharmx edited this page May 11, 2024 · 11 revisions

A cycle command.

Select the next Mark in the marks list.

local index = 0

vim.api.nvim_create_user_command("CycleMarkP", function()
  local _, branch = require("track.util").root_and_branch()
  if not branch then return end
  index = math.max(index, math.min(#branch.views, index)) % #branch.views + 1
  vim.cmd.OpenMark(index)
end, {})

vim.api.nvim_create_user_command("CycleMarkN", function()
  local _, branch = require("track.util").root_and_branch()
  if not branch then return end
  index = (index - 2 + #branch.views) % #branch.views + 1
  vim.cmd.OpenMark(index)
end, {})

Select shortcuts.

Global mark selection mappings similar to harpoons. Depends on xdg-open.

for serial = 1, 9 do
  local key = tostring(serial)
  vim.keymap.set("n", "<space>" .. key, "<cmd>OpenMark " .. key .. "<cr>")
end

External runners.

Open PDFs, audio files, video files, etc.

local media = {
  ["jpeg"] = true,
  ["jpg"] = true,
  ["png"] = true,
  ["mp3"] = true,
  ["mp4"] = true,
  ["flac"] = true,
  ["mkv"] = true,
  ["pdf"] = true,
}

local function open(mark)
  if mark.type == "file" and media[vim.fn.fnamemodify(mark.uri, ":e")] then
    vim.fn.jobstart({ "xdg-open", mark:absolute() }, { detach = true })
  else
    require("track.util").open_entry(mark)
  end
end

require("track").setup({
  pickers = {
    pad = {
      hooks = { on_choose = open },
    },
    views = {
      hooks = {
        on_choose = function(self)
          local entries = vim.F.if_nil(self:get_multi_selection(), {})
          if #entries == 0 then table.insert(entries, self:get_selection()) end
          for _, entry in ipairs(entries) do open(entry.value) end
        end,
      },
    },
  },
})
Clone this wiki locally