img-paste-devs/img-paste.vim

wsl 2 wslpath -m "No such file or directory"

k4fka opened this issue · 4 comments

k4fka commented

Hi.
I'm running ubunu and WSL v2. When pasting an image from the clipboard I was getting an error thrown by the wslpath command. When this command is executed to resolve a path of a nonexistent file you get a "No such file or directory" error. This happens when trying to resolve the path AND the new image name.

I was able to work around this by resolving the folder path first and then appending the new image name

 33 function! s:SaveFileTMPWSL(imgdir, tmpname) abort
 34     let folder_path = substitute(system("wslpath -m ".a:imgdir), '\n\+$', '', '')
 35     let tmpfile = folder_path . '/' . a:tmpname . '.png'
 36
 37
 38     let clip_command = "Add-Type -AssemblyName System.Windows.Forms;"
 39     let clip_command .= "if ([Windows.Forms.Clipboard]::ContainsImage()) {"
 40     let clip_command .= "[Windows.Forms.Clipboard]::GetImage().Save(\\\""
 41     let clip_command .= tmpfile ."\\\", [System.Drawing.Imaging.ImageFormat]::Png) }"
 42     let clip_command = "powershell.exe -sta \"".clip_command. "\""
 43
 44     call system(clip_command)
 45     if v:shell_error == 1
 46         echo "error"
 47         return 1
 48     else
 49         return tmpfile
 50     endif
 51 endfunction

Hi! So in WSL 2 the old method is changed, right? Can you please open a PR adding this check as an additional for WSL?

related to #33

Want to try using this patch to see if it resolves your issues? If anyone with WSL wants to test please let me know so we can merge #36.

I'll close the issue as the corresponding pr is merged. If any bug reappear, feel free to open