Skip to content

Commit

Permalink
fix(utils): use Papis opentool if defined (closes #25)
Browse files Browse the repository at this point in the history
  • Loading branch information
jghauser committed Jun 4, 2024
1 parent 9017f38 commit 4e4b855
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 9 deletions.
4 changes: 2 additions & 2 deletions lua/papis/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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", "")
Expand Down
19 changes: 13 additions & 6 deletions lua/papis/sqlite-wrapper.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion lua/papis/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 4e4b855

Please sign in to comment.