zest.lua (910B)
1 local api = vim.api 2 local fn = vim.fn 3 4 local azyui = require 'azy.ui' 5 local asinks = require 'azy.sinks' 6 7 local M = {} 8 9 local ZPATH = vim.fn.expand "$HOME" .. "/obsvault/" 10 11 local function zpath(...) 12 return ZPATH .. "/" .. table.concat({ ... }, "/") 13 end 14 15 local function list_files() 16 local ret = {} 17 18 for index, path in ipairs(vim.fs.find(function(path) return vim.endswith(path, ".md") end, { path = ZPATH, limit = math.huge })) do 19 ret[index] = { 20 search_text = fn.fnamemodify(path, ":t:r"), 21 extra = path, 22 } 23 end 24 25 return ret 26 end 27 28 function M.find_file(name) 29 for _, file in ipairs(list_files()) do 30 vim.pretty_print(file) 31 if file.search_text == name then 32 return file 33 end 34 end 35 end 36 37 local function zest_sink(element, modifiers) 38 asinks.open_file({ search_text = element.extra }, modifiers) 39 end 40 41 function M.open() 42 azyui.create(list_files(), zest_sink) 43 end 44 45 return M