From 38738a6527d2d571d149bda36e74bdb9e2f0743c Mon Sep 17 00:00:00 2001 From: DefaultGen Date: Sun, 9 Jun 2024 03:48:26 -0400 Subject: Added cursed search function --- lua/simple-denote/search.lua | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 lua/simple-denote/search.lua (limited to 'lua/simple-denote/search.lua') diff --git a/lua/simple-denote/search.lua b/lua/simple-denote/search.lua new file mode 100644 index 0000000..eab25dd --- /dev/null +++ b/lua/simple-denote/search.lua @@ -0,0 +1,40 @@ +local M = {} + +function M.search(options) + local width = vim.o.columns - 8 + local height = vim.o.lines - 8 + + vim.api.nvim_open_win( + vim.api.nvim_create_buf(false, true), + true, + { + relative = 'editor', + style = 'minimal', + border = 'rounded', + noautocmd = true, + width = width, + height = height, + col = math.min((vim.o.columns - width) / 2), + row = math.min((vim.o.lines - height) / 2 - 1), + } + ) + local file = vim.fn.tempname() + -- This feels like the wrong way to call a script from a relative path + local lua_file_path = debug.getinfo(1, "S").source:sub(2) + local lua_file_dir = vim.fn.fnamemodify(lua_file_path, ":h") + local script_path = lua_file_dir .. "/scripts/search.sh" + if not script_path then + error("Script not found") + end + vim.api.nvim_command('startinsert') + vim.fn.termopen(script_path .. " " .. options.dir .. " > " .. file, { + on_exit = function(jobid, data, event) + vim.api.nvim_command('bdelete!') + local f = io.open(file, 'r') + local stdout = f:read('*all') + f:close() + os.remove(file) + vim.api.nvim_command('edit ' .. stdout) + end}) +end +return M -- cgit v1.2.3