25022024-1
This commit is contained in:
parent
609a054b18
commit
698fe1695f
2 changed files with 56 additions and 12 deletions
|
@ -1,18 +1,7 @@
|
||||||
local mapvimkey = require("utils.keymapper").mapvimkey
|
local mapvimkey = require("utils.keymapper").mapvimkey
|
||||||
|
local copy_filename_to_clipboard = require("utils.telescope_addons").copy_filename_to_clipboard
|
||||||
|
|
||||||
local config = function()
|
local config = function()
|
||||||
local actions = require("telescope.actions")
|
|
||||||
local action_state = require("telescope.actions.state")
|
|
||||||
-- copy file name from search
|
|
||||||
local copy_filename_to_clipboard = function(prompt_bufnr)
|
|
||||||
local selection = action_state.get_selected_entry()
|
|
||||||
local filename_part = vim.split(selection.value, ":")[1]
|
|
||||||
vim.fn.setreg("*", filename_part)
|
|
||||||
vim.fn.setreg("+", filename_part)
|
|
||||||
print("Copied filename: " .. filename_part)
|
|
||||||
actions.close(prompt_bufnr)
|
|
||||||
end
|
|
||||||
|
|
||||||
local telescope = require("telescope")
|
local telescope = require("telescope")
|
||||||
telescope.setup({
|
telescope.setup({
|
||||||
defaults = {
|
defaults = {
|
||||||
|
|
55
global/.config/nvim/lua/utils/telescope_addons.lua
Normal file
55
global/.config/nvim/lua/utils/telescope_addons.lua
Normal file
|
@ -0,0 +1,55 @@
|
||||||
|
local action_state = require("telescope.actions.state")
|
||||||
|
local actions = require("telescope.actions")
|
||||||
|
local mapvimkey = require("utils.keymapper").mapvimkey
|
||||||
|
|
||||||
|
local M = {}
|
||||||
|
|
||||||
|
local function paste_titled_link()
|
||||||
|
return function(prompt_bufnr)
|
||||||
|
actions.close(prompt_bufnr)
|
||||||
|
local selection = action_state.get_selected_entry()
|
||||||
|
local parts = vim.split(selection.value, ":")
|
||||||
|
local filename_part = parts[1]
|
||||||
|
local title = parts[#parts]:match("^%s*(.-)%s*$")
|
||||||
|
local link = "[" .. title .. "](" .. filename_part .. ")"
|
||||||
|
vim.api.nvim_put({ link }, "", true, true)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local function paste_link()
|
||||||
|
return function(prompt_bufnr)
|
||||||
|
actions.close(prompt_bufnr)
|
||||||
|
local selection = action_state.get_selected_entry()
|
||||||
|
local filename_part = vim.split(selection.value, ":")[1]
|
||||||
|
local link = "[[" .. filename_part .. "]]"
|
||||||
|
vim.api.nvim_put({ link }, "", true, true)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
M.search_title = function()
|
||||||
|
require("telescope.builtin").live_grep({
|
||||||
|
prompt_title = "Search by zettel title",
|
||||||
|
default_text = "^title: ",
|
||||||
|
attach_mappings = function(_, map)
|
||||||
|
map("n", "<c-i>", paste_titled_link())
|
||||||
|
map("i", "<c-i>", paste_titled_link())
|
||||||
|
map("n", "<c-u>", paste_link())
|
||||||
|
map("i", "<c-u>", paste_link())
|
||||||
|
return true
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
end
|
||||||
|
|
||||||
|
M.copy_filename_to_clipboard = function(prompt_bufnr)
|
||||||
|
local selection = action_state.get_selected_entry()
|
||||||
|
local filename_part = vim.split(selection.value, ":")[1]
|
||||||
|
vim.fn.setreg("*", filename_part)
|
||||||
|
vim.fn.setreg("+", filename_part)
|
||||||
|
print("Copied filename: " .. filename_part)
|
||||||
|
actions.close(prompt_bufnr)
|
||||||
|
end
|
||||||
|
|
||||||
|
vim.api.nvim_create_user_command("SearchZettelTitle", M.search_title, {})
|
||||||
|
mapvimkey("<leader>fm", "SearchZettelTitle", "Search by zettel title")
|
||||||
|
|
||||||
|
return M
|
Loading…
Add table
Reference in a new issue