2023-10-10 20:02:50 +02:00
|
|
|
local pickers = require("telescope.pickers")
|
|
|
|
local actions = require "telescope.actions"
|
2024-01-17 13:01:32 +01:00
|
|
|
local action_state = require("telescope.actions.state")
|
2023-10-10 20:02:50 +02:00
|
|
|
local finders = require("telescope.finders")
|
|
|
|
local conf = require("telescope.config").values
|
|
|
|
|
2024-01-17 13:01:32 +01:00
|
|
|
local root_path = '/home/user/Workspace/DnD/Lumentis Campaign Setting'
|
2023-10-10 20:02:50 +02:00
|
|
|
|
|
|
|
local function get_title(file)
|
|
|
|
for line in io.lines(file) do
|
|
|
|
line = string.gsub(line, "#", "")
|
|
|
|
line = string.gsub(line, "^%s*", "")
|
|
|
|
line = string.gsub(line, "%s*$", "")
|
|
|
|
return line
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2024-01-17 13:01:32 +01:00
|
|
|
local function choose_link(opts, titles, links)
|
2023-10-10 20:02:50 +02:00
|
|
|
opts = opts or {}
|
|
|
|
pickers.new(opts, {
|
|
|
|
prompt_title = "Choose a file",
|
|
|
|
finder = finders.new_table {
|
|
|
|
results = titles
|
|
|
|
},
|
|
|
|
sorter = conf.generic_sorter(opts),
|
|
|
|
attach_mappings = function(prompt_bufnr, _)
|
|
|
|
actions.select_default:replace(function()
|
|
|
|
actions.close(prompt_bufnr)
|
|
|
|
local selection = action_state.get_selected_entry()
|
|
|
|
vim.api.nvim_put({ links[selection['index']] }, "", false, true)
|
|
|
|
end)
|
|
|
|
return true
|
|
|
|
end,
|
|
|
|
}):find()
|
|
|
|
end
|
|
|
|
|
2024-01-17 13:01:32 +01:00
|
|
|
local function insert_link()
|
2023-10-10 20:02:50 +02:00
|
|
|
local scan = require("plenary.scandir").scan_dir(root_path)
|
|
|
|
local titles = {}
|
|
|
|
local links = {}
|
|
|
|
for _, v in ipairs(scan) do
|
|
|
|
if v:match("^.+(%..+)$") == ".md" then
|
|
|
|
local absolute_filename = string.sub(v, root_path:len()+1, v:len())
|
|
|
|
local title = get_title(v)
|
|
|
|
if title:len() > 0 then
|
|
|
|
local link = "[" .. title .. "](" .. absolute_filename .. ")"
|
|
|
|
table.insert(titles, title)
|
|
|
|
table.insert(links, link)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
choose_link(require("telescope.themes").get_dropdown{}, titles, links)
|
|
|
|
end
|
|
|
|
|
2024-01-17 13:01:32 +01:00
|
|
|
return {
|
|
|
|
'vimwiki/vimwiki',
|
|
|
|
dependencies = {'nvim-lua/plenary.nvim', 'nvim-telescope/telescope.nvim'},
|
|
|
|
init = function ()
|
|
|
|
vim.g.vimwiki_list = {{path = '~/Workspace/DnD/Lumentis Campaign Setting/', syntax = 'markdown', ext = '.md'}}
|
|
|
|
vim.g.vimwiki_key_mappings = { table_mappings = 0 }
|
|
|
|
vim.g.vimwiki_markdown_link_ext = 1
|
|
|
|
vim.g.vimwiki_global_ext = 0
|
|
|
|
end,
|
|
|
|
lazy = false,
|
|
|
|
keys = {
|
|
|
|
{"<leader>l", insert_link},
|
|
|
|
{"<leader>l", insert_link, mode="i"}
|
|
|
|
}
|
|
|
|
}
|