[Feat] adding support to copy to clipboard in WSL
Add to dependencies to get system info, to check if is wsl and the current pretty name of the distro.
If wsl is getting used, this should create the image as a temp file inside wsl, then use powershell to copy it to the clipboard, and then it deletes the image from the tmp directory.
this is my first time doing rust so sorry if the code does not follow some good practice, I'm open to any kind of feedback, if something needs to be changed to match the standard in the rest of the codebase just leave a comment and I will fix it
Hey @jhonnyV-V, thx for this PR. Can you run CodeSnap.nvim on WSL? there are a few issues describe that they can't run CodeSnap.nvim on WSL, it would be great if you could add some documents for the WSL install/usage guide
Hi @mistricky, yes I can run it without problems and configuring things inside of WSL, I could give it a try
Hi @jhonnyV-V, is there any update for https://github.com/mistricky/codesnap.nvim/issues/73#issuecomment-2057344317? It seems like not work perfectly.
Hi @mistricky I haven't been able to try to tackle this issue, I will try this week, it seems like a rust issue, where rust fails to access the clipboard, I have to test this more,
WSL's clipboard is tricky. Hopefully this brings some light: https://lib.rs/crates/clipboard-anywhere
I'll keep an eye on this, I'd love to use this plugin but I primarily work in WSL.
Thanks for the PR!
well I finally had the time to continue, I think this should be working now, the error was a pretty simple thing
@brandonsturgeon @mistricky any feedback is useful, maybe if this works finally #73 could be closed
Nice!
How can I test this on my setup? Do I just point my plugin manager to your fork+branch?
Nice!
How can I test this on my setup? Do I just point my plugin manager to your fork+branch?
yes, that should work
I'm currently fixing a couple of things that were still wrong and could cause issues under some cases, there is a problem and is that detecting how is named the linux distro in the \wsl$ directory is hard, currently I'm relying on a crate to get a couple of good guesses, but if the user changed the name or the name for the distro is different, this could not work, maybe in the future reading this from an env variable could be solution
I'm currently adding a check for this reason to try two options that should be good enough for most cases, and adding some string escaping because it was causing some problems
btw I made some test for the things I added If @mistricky wants I could commit them also, and I could just make early returns if the user is not in wsl
btw I made some test for the things I added If @mistricky wants I could commit them also, and I could just make early returns if the user is not in wsl
Add test cases is really great! Can you add information in README on how to setup CodeSnap on WSL and other important considerations of WSL?
Hi @jhonnyV-V, I have noticed that you only updated the copy.rs, the copy.rs is used to perform the copy action. If users want to save snapshot in somewhere, the save.rs should be updated.
@mistricky Hi @mistricky, yes, I only updated the copy.rs, that is the only problem that I found in the plugin with wsl, the save workflow works fine, I could add a small example in the readme of how to store in another disk from wsl
@mistricky Hi @mistricky, yes, I only updated the copy.rs, that is the only problem that I found in the plugin with wsl, the save workflow works fine, I could add a small example in the readme of how to store in another disk from wsl
Hi @jhonnyV-V, thx for ur amazing job! I don't have Windows machine, Can u help test if it works fine on Windows? or can someone help? @brandonsturgeon @mgastonportillo thx guys.
If everything is OK and also there is no further work in this PR, I'll merge it into main branch.
@mistricky Hi @mistricky, yes, I only updated the copy.rs, that is the only problem that I found in the plugin with wsl, the save workflow works fine, I could add a small example in the readme of how to store in another disk from wsl
Hi @jhonnyV-V, thx for ur amazing job! I don't have Windows machine, Can u help test if it works fine on Windows? or can someone help? @brandonsturgeon @mgastonportillo thx guys.
If everything is OK and also there is no further work in this PR, I'll merge it into main branch.
I tested and it's not working for me. I'll attach a video with the spec and an example of it not working. This is my clipboard config:
if vim.fn.has "wsl" then
local copy = "clip.exe"
local paste = 'pwsh.exe -c [Console]::Out.Write($(Get-Clipboard -Raw).tostring().replace("`r", ""))'
vim.g.clipboard = {
name = "wslclipboard",
copy = { ["+"] = copy, ["*"] = copy },
paste = { ["+"] = paste, ["*"] = paste },
cache_enabled = 0,
}
end
And here the video: https://github.com/mistricky/codesnap.nvim/assets/106234166/446737fd-e3df-4473-9862-d753c0da1ad7
And just in case:
@mgastonportillo you are right, somehow I managed to break everything by adding the tests, the last working commit is the 3a74e416, I will fix this soon
@mgastonportillo you are right, somehow I managed to break everything by adding the tests, the last working commit is the 3a74e416, I will fix this soon
Would you like me to test again? I just got free
Edit: I tested again around the time I sent this message, pulled the new commits and it wasn't working yet. I assumed it still needs some fixes to be implemented.
If you need me to test again, just let me know and I'll try my best to assist with it.
Hi @jhonnyV-V, do you have time to take another look at this PR? It seems like there are still few issues
@mistricky well, sorry for the absence, for reasons I migrated to linux and in a completely unrelated note my windows installation broke so I am not able to keep developing on this, so I will comment on the issues I found and could not really solve in case someone else is able to find the problem and fix this
this should work locally, the issue is for some reason that escaped my comprehension when is installed from a github branch instead of using a path to a directory it will start failing to copy to the clipboard, not really sure what is the actual error, I didn't get to debug this before my windows problem happen, probably the best way to try this is adding a bunch of logging and log all the powershell outputs and commit that, then using that branch with the commit to install the extension
I believe that this could be a problem with permissions, maybe windows does not like when something you downloaded from the internet attempt to execute arbitrary commands on windows from wsl