feat: add xsel for pasting images

* https://github.com/renerocksai/telekasten.nvim/issues/131

- fixed a problem with `xclip` in linux (added `xsel`)

* removed debug info

* xclip
This commit is contained in:
fz0x1
2024-02-26 14:28:46 -05:00
committed by GitHub
parent 1f725fca21
commit 434e74ad30

View File

@@ -372,7 +372,22 @@ local function imgFromClipboard()
end end
local get_paste_command local get_paste_command
if vim.fn.executable("xclip") == 1 then if vim.fn.executable("xsel") == 1 then
get_paste_command = function(dir, filename)
local _image_path = vim.fn.system("xsel --clipboard --output")
local image_path = _image_path:gsub("file://", "")
if
vim.fn
.system("file --mime-type -b " .. image_path)
:gsub("%s+", "")
== "image/png"
then
return "cp " .. image_path .. " " .. dir .. "/" .. filename
else
return ""
end
end
elseif vim.fn.executable("xclip") == 1 then
get_paste_command = function(dir, filename) get_paste_command = function(dir, filename)
return "xclip -selection clipboard -t image/png -o > " return "xclip -selection clipboard -t image/png -o > "
.. dir .. dir
@@ -397,7 +412,7 @@ local function imgFromClipboard()
return return
end end
-- TODO: check `xclip -selection clipboard -t TARGETS -o` for the occurence of `image/png` -- TODO: check `xclip -selection clipboard -t TARGETS -o` for the occurrence of `image/png`
-- using plenary.job::new():sync() with on_stdout(_, data) unfortunately did some weird ASCII translation on the -- using plenary.job::new():sync() with on_stdout(_, data) unfortunately did some weird ASCII translation on the
-- data, so the PNGs were invalid. It seems like 0d 0a and single 0a bytes were stripped by the plenary job: -- data, so the PNGs were invalid. It seems like 0d 0a and single 0a bytes were stripped by the plenary job:
@@ -1578,7 +1593,7 @@ local function RenameNote()
local fname = M.Cfg.home .. "/" .. newname .. M.Cfg.extension local fname = M.Cfg.home .. "/" .. newname .. M.Cfg.extension
local fexists = fileutils.file_exists(fname) local fexists = fileutils.file_exists(fname)
if fexists then if fexists then
tkutils.print_error("File alreay exists. Renaming abandonned") tkutils.print_error("File already exists. Renaming abandoned")
return return
end end