paste_img from a copied file path #845
Replies: 6 comments
|
I did not write the image paste part and have little knowledge on it, so I did not fully get your question are you asking |
Yes, I mean exactly that. For example, when I copy a file, from Thunar file manager, I get this: $ xclip -o -selection clipboard -t STRING
/path/to/image.jpgIn this case, attempt to get an image data from clipboard would fail: $ xclip -o -selection clipboard -t image/png
Error: target image/png not available
$ echo $?
1Returning exit code If there is no image data in clipboard, then we could try to check if clipboard contains a string, which is a path, to an existing file, which is also an image file. If this is the case, then obsidian.nvim could simple copy it to the Vault. |
|
I am currently working on refactoring, expanding, and writing test cases for I'm hoping to create a pull request for that by the end of the day. I could also take a look into expanding this feature after I am done with that, unless this is something you would want to work on yourself. |
|
I'm not fluent in Lua, so I would be happy if you would work on this feature after you're done with the current pull request. |
|
closing this one for now, since I thing although the feature seems intuitive once you say it, it would be better for the paste img module to have less add on logic, since it is something that needs heavy refactor, and for now just use the solution in #844 |
|
for reference since I'll transform this to a discussion: local log = require "obsidian.log"
local paste_from_path = function()
local path = vim.trim(vim.fn.getreg "+")
if path == "" then
return log.warn "Clipboard is empty"
end
local stat_path = vim.startswith(path, "file://") and vim.uri_to_fname(path) or path
if not vim.uv.fs_stat(stat_path) then
return log.warn("Clipboard does not contain a valid path: %s", path)
end
vim.schedule(function()
require("obsidian.attachment").add(path, { insert = true })
end)
end |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
🚀 The feature, motivation and pitch
I want to copy just image path to an existing file. And I would like to use
paste_imgto copy that image, to Obsidian's files directory.For example, if I copy
/tmp/image.jpg, then running:Obsidian paste_imgwould copy/tmp/image.jpgto~/vault/images/image.jpg.Alternatives
An alternative would be, to always copy image to clipboard first, something like this:
convert /tmp/image.jpg png:- | xclip -i -selection clipboard -target image/pngBut this involves image conversion and adding it to clipboard, then existing
paste_imgfunctionality would work.Or I could simply copy image file to vault manually and then use it in .md file, but that is not very convenient.
All reactions