From 4e4b855f2132da8c1570ef7710e1fd71c73506d2 Mon Sep 17 00:00:00 2001 From: jghauser Date: Tue, 4 Jun 2024 12:48:09 +0200 Subject: [PATCH] fix(utils): use Papis opentool if defined (closes #25) --- lua/papis/config.lua | 4 ++-- lua/papis/sqlite-wrapper.lua | 19 +++++++++++++------ lua/papis/utils.lua | 6 +++++- 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/lua/papis/config.lua b/lua/papis/config.lua index 5e56887..ed768b7 100644 --- a/lua/papis/config.lua +++ b/lua/papis/config.lua @@ -61,6 +61,7 @@ local default_config = { ) end, init_filetypes = { "markdown", "norg", "yaml" }, + papis_conf_keys = { "info-name", "notes-name", "dir", "opentool" }, ["formatter"] = { format_notes_fn = function(entry) local title_format = { @@ -152,13 +153,12 @@ local M = vim.deepcopy(default_config) ---@param testing_session boolean #If true, will use testing papis conf ---@return table #A table { info_name = val, dir = val } function M:get_papis_py_conf(testing_session) - local papis_conf_keys = { "info-name", "notes-name", "dir" } local papis_py_conf_new = {} local testing_conf_path = "" if testing_session then testing_conf_path = "-c ./tests/papis_config " end - for _, key in ipairs(papis_conf_keys) do + for _, key in ipairs(self["papis_conf_keys"]) do local handle = io.popen("papis " .. testing_conf_path .. "config " .. key) if handle then papis_py_conf_new[string.gsub(key, "-", "_")] = string.gsub(handle:read("*a"), "\n", "") diff --git a/lua/papis/sqlite-wrapper.lua b/lua/papis/sqlite-wrapper.lua index d6e726c..31a39df 100644 --- a/lua/papis/sqlite-wrapper.lua +++ b/lua/papis/sqlite-wrapper.lua @@ -99,12 +99,19 @@ M.state = M:tbl("state", { tag_format = { "text", default = nil }, }) -M.config = M:tbl("config", { - id = true, - info_name = { "text", default = nil }, - notes_name = { "text", default = nil }, - dir = { "text", default = nil }, -}) + +---Creates the schema of the config table +---@return table #The config table schema +local function get_config_tbl_schema() + local tbl_schema = { id = true, } + for _, key in ipairs(config["papis_conf_keys"]) do + local sanitized_key = string.gsub(key, "-", "_") + tbl_schema[sanitized_key] = { "text", default = nil } + end + return tbl_schema +end + +M.config = M:tbl("config", get_config_tbl_schema()) ---Adds common methods to tbls ---@param tbls table #Set of tables that should have methods added diff --git a/lua/papis/utils.lua b/lua/papis/utils.lua index 63f5548..9f1baa3 100644 --- a/lua/papis/utils.lua +++ b/lua/papis/utils.lua @@ -64,9 +64,13 @@ end -- Open file outside neovim ---@param path string #Path to the file function M.do_open_file_external(path) + local opentool = require("papis.sqlite-wrapper").config:get_value({ id = 1 }, "opentool") local command local args - if is_windows then + if opentool then + command = opentool + args = { path } + elseif is_windows then command = "rundll32.exe" args = { "url.dll,FileProtocolHandler", path } else