Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix/wsl error #44

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion API.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ require 'clipboard-image.init'.setup()
| `get_os` | | `os_name`: `string`<br>Windows, Linux, Darwin, etc | Reference https://vi.stackexchange.com/a/2577/33116 |
| `get_clip_command` | | `cmd_check`: `string`<br>`cmd_paste`: `string` | Get command to *check* and *paste* clipboard content |
| `get_clip_content` | `command`: `string`<br>*command to check `clip_content`* | `usable_config`: `table` | Will be used in `utils.is_clipboard_img` to check if image data exist |
| `is_clipboard_img` | `content`: `string`<br> *clipboard-content* | `loaded_config`: `table` | Check if clipboard contain image data<br> See also: [Data URI scheme](https://en.wikipedia.org/wiki/Data-URI-scheme) |
| `is_clipboard_img` | `content`: `table`<br> *clipboard-content* | `loaded_config`: `table` | Check if clipboard contain image data<br> See also: [Data URI scheme](https://en.wikipedia.org/wiki/Data-URI-scheme) |
| `resolve_dir` | `dir`: `string` \| `table`<br> `path_separator`: `string`<br> | `full_path`: `string` | Resolve any complicated pathing |
| `create_dir` | `dir`: `string` *dir path* | | Create directory |
| `get_img_path` | `dir`: `string`<br> `img_name`: `string`<br> `is_txt?`: `"txt"`<br> *Wether `img_path` will be used as inserted text or to copy image because Windows has different path separator* | `img_path`: `string` | Get image's path<br>NOTE: Probably will replace `is_text` with `path_separator` |
Expand Down
6 changes: 3 additions & 3 deletions lua/clipboard-image/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ M.get_clip_command = function()
cmd_paste = "pngpaste '%s'"
elseif this_os == "Windows" or this_os == "Wsl" then
cmd_check = "Get-Clipboard -Format Image"
cmd_paste = "$content = " .. cmd_check .. ";$content.Save('%s', 'png')"
cmd_paste = "(" .. cmd_check .. ").Save('%s', 'png')"
cmd_check = 'powershell.exe "' .. cmd_check .. '"'
cmd_paste = 'powershell.exe "' .. cmd_paste .. '"'
end
Expand All @@ -56,14 +56,14 @@ end

---Check if clipboard contain image data
---See also: [Data URI scheme](https://en.wikipedia.org/wiki/Data_URI_scheme)
---@param content string #clipboard content
---@param content table #clipboard content
M.is_clipboard_img = function(content)
local this_os = M.get_os()
if this_os == "Linux" and vim.tbl_contains(content, "image/png") then
return true
elseif this_os == "Darwin" and string.sub(content[1], 1, 9) == "iVBORw0KG" then -- Magic png number in base64
return true
elseif this_os == "Windows" or this_os == "Wsl" and content ~= nil then
elseif this_os == "Windows" or this_os == "Wsl" and next(content) ~= nil then
return true
end
return false
Expand Down