diff --git a/lua/img-clip/clipboard.lua b/lua/img-clip/clipboard.lua index 4e7c5c1..e252427 100644 --- a/lua/img-clip/clipboard.lua +++ b/lua/img-clip/clipboard.lua @@ -70,26 +70,28 @@ M.content_is_image = function() return false end ----@param file_path string ----@return boolean M.save_image = function(file_path) local cmd = M.get_clip_cmd() + local process_cmd = config.get_opt("process_cmd") + if process_cmd ~= "" then + process_cmd = "| " .. process_cmd .. " " + end -- Linux (X11) if cmd == "xclip" then - local command = string.format('xclip -selection clipboard -o -t image/png > "%s"', file_path) + local command = string.format('xclip -selection clipboard -o -t image/png %s> "%s"', process_cmd, file_path) local _, exit_code = util.execute(command) return exit_code == 0 -- Linux (Wayland) elseif cmd == "wl-paste" then - local command = string.format('wl-paste --type image/png > "%s"', file_path) + local command = string.format('wl-paste --type image/png %s> "%s"', process_cmd, file_path) local _, exit_code = util.execute(command) return exit_code == 0 -- MacOS (pngpaste) which is faster than osascript elseif cmd == "pngpaste" then - local command = string.format('pngpaste "%s"', file_path) + local command = string.format('pngpaste - %s> "%s"', process_cmd, file_path) local _, exit_code = util.execute(command) return exit_code == 0 @@ -98,7 +100,10 @@ M.save_image = function(file_path) local command = string.format( [[osascript -e 'set theFile to (open for access POSIX file "%s" with write permission)' ]] .. [[-e 'try' -e 'write (the clipboard as «class PNGf») to theFile' -e 'end try' ]] - .. [[-e 'close access theFile']], + .. [[-e 'close access theFile' -e 'do shell script "cat %s %s> %s"']], + file_path, + file_path, + process_cmd, file_path ) local _, exit_code = util.execute(command) diff --git a/lua/img-clip/paste.lua b/lua/img-clip/paste.lua index f588885..3f7e77f 100644 --- a/lua/img-clip/paste.lua +++ b/lua/img-clip/paste.lua @@ -167,10 +167,12 @@ M.paste_image_from_clipboard = function() return false end - local output, exit_code = fs.process_image(file_path) - if exit_code ~= 0 then - util.warn("Could not process image.", true) - util.warn("Output: " .. output, true) + if util.has("wsl") then + local output, exit_code = fs.process_image(file_path) + if exit_code ~= 0 then + util.warn("Could not process image.", true) + util.warn("Output: " .. output, true) + end end if not markup.insert_markup(file_path) then