Skip to content

Commit

Permalink
refactor: fix dir_path option in config and add comments
Browse files Browse the repository at this point in the history
  • Loading branch information
HakonHarnes committed Dec 8, 2023
1 parent 53ef988 commit 00561b6
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions lua/img-clip/config.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
local M = {}

local defaults = {
dir_path = "assets/",
dir_path = "assets",
filename = "%Y-%m-%d-%H-%M-%S",
prompt_for_filename = true,
include_filepath_in_prompt = false,
Expand All @@ -22,24 +22,28 @@ M.get_option = function(key, opts)
local ft = vim.bo.filetype
local val

-- check options passed explicitly to pasteImage function
if opts and opts[key] ~= nil then
val = opts[key]

-- Check for filetype-specific option
-- otherwise chck for filetype-specific option
elseif M.options[ft] and M.options[ft][key] ~= nil then
val = M.options[ft][key]

-- otherwise check for global option
elseif M.options[key] ~= nil then
val = M.options[key]

-- return nil if no option found
else
vim.notify("No option found for " .. key .. ".", vim.log.levels.WARN, { title = "img-clip" })
return nil
end

-- Check if the option is a function and execute it
if type(val) == "function" then
return val() -- Execute the function and return its result
return val() -- execute the function and return its result
else
return val -- Return the option value directly
return val
end
end

Expand Down

0 comments on commit 00561b6

Please sign in to comment.