okbob / pspg

Unix pager (with very rich functionality) designed for work with tables. Designed for PostgreSQL, but MySQL is supported too. Works well with pgcli too. Can be used as CSV or TSV viewer too. It supports searching, selecting rows, columns, or block and export selected area to clipboard.
BSD 2-Clause "Simplified" License
2.43k stars 85 forks source link

Add support for clip.exe inside WSL2 #242

Closed gus-sipc closed 5 months ago

gus-sipc commented 5 months ago

Hi,

Would it be possible to add support for a new 4th option for the --clipboard-app parameter? In this way, copy-to-clipboard should work well inside WSL2 (Windows Subsystem for Linux 2).

With this new 4th option, all the options available would be the following:

In WSL2, the clip.exe program is located in /mnt/c/WINDOWS/system32/clip.exe which is usually already available since WSL2 automatically adds /mnt/c/WINDOWS/system32 to the PATH environment variable.

Thank you for this fantastic tool!

okbob commented 5 months ago

please check b3d96ff0729a806d01b5dfff43135449f4dad3dc

gus-sipc commented 5 months ago

I've tried using this new version of pspg with the --clipboard-app=4 parameter, and when I press the Ins key to copy some information to the clipboard, I receive the following error:

Cannot write to clipboard (clip.exe) (press any key)

clip.exe is available and works in the same way as pbcopy; for example:

echo Test | clip.exe

... effectively copies the Test text to the clipboard.

Is it possible for pspg to use clip.exe in the same way that it is using pbcopy?

okbob commented 5 months ago

please try 463ab29b596c316c153acfbfc9a584fe6668073f

gus-sipc commented 5 months ago

I've tried using this new version of pspg with the --clipboard-app=4 parameter, and when I press the Ins key to copy some information to the clipboard, the text is now copied correctly. Thank you for this useful addition to pspg!

If I ran pspg without the --clipboard-app=4 parameter, the clipboard detection algorithm automatically selects xclip instead of clip.exe, since xclip is also available in my WSL2 environment, but it doesn't work because I don't have an X-server running. The error I receive when I press the Ins key in this case is:

 Cannot write to clipboard (Error: Can't open display: :0) (press any key)

Is it possible for the clipboard detection algorithm to look for clip.exe before looking for xclip, so that in a WSL2 environment clip.exe can be automatically selected?

okbob commented 5 months ago

pá 12. 4. 2024 v 17:18 odesílatel Gus @.***> napsal:

I've tried using this new version of pspg with the --clipboard-app=4 parameter, and when I press the Ins key to copy some information to the clipboard, the text is now copied correctly. Thank you for this useful addition to pspg!

If I ran pspg without the --clipboard-app=4 parameter, the clipboard detection algorithm automatically selects xclip instead of clip.exe, since xclip is also available in my WSL2 environment, but it doesn't work because I don't have an X-server running. The error I receive when I press the Ins key in this case is:

Cannot write to clipboard (Error: Can't open display: :0) (press any key)

Is it possible for the clipboard detection algorithm to look for clip.exe before looking for xclip, so that in a WSL2 environment clip.exe can be automatically selected?

yes, it does

https://github.com/okbob/pspg/blob/463ab29b596c316c153acfbfc9a584fe6668073f/src/pspg.c#L1832

— Reply to this email directly, view it on GitHub https://github.com/okbob/pspg/issues/242#issuecomment-2051964957, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAEFO46LGBQ5C6XZZNKDKLDY473M3AVCNFSM6AAAAABF62ZQLCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDANJRHE3DIOJVG4 . You are receiving this because you commented.Message ID: @.***>

okbob commented 5 months ago

released in 5.8.3

Thank you for checks

okbob commented 5 months ago

pá 12. 4. 2024 v 17:18 odesílatel Gus @.> napsal: I've tried using this new version of pspg with the --clipboard-app=4 parameter, and when I press the Ins key to copy some information to the clipboard, the text is now copied correctly. Thank you for this useful addition to pspg! If I ran pspg without the --clipboard-app=4 parameter, the clipboard detection algorithm automatically selects xclip instead of clip.exe, since xclip is also available in my WSL2 environment, but it doesn't work because I don't have an X-server running. The error I receive when I press the Ins key in this case is: Cannot write to clipboard (Error: Can't open display: :0) (press any key) Is it possible for the clipboard detection algorithm to look for clip.exe before looking for xclip, so that in a WSL2 environment clip.exe can be automatically selected? yes, it does https://github.com/okbob/pspg/blob/463ab29b596c316c153acfbfc9a584fe6668073f/src/pspg.c#L1832 — Reply to this email directly, view it on GitHub <#242 (comment)>, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAEFO46LGBQ5C6XZZNKDKLDY473M3AVCNFSM6AAAAABF62ZQLCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDANJRHE3DIOJVG4 . You are receiving this because you commented.Message ID: @.>

There will be always conflict - what clipboard application should be used (when there are more possibilities). This is reason why there are an option --clipboard-app. Maybe I can do check if xserver is defined or not, if this is possible by some way.

okbob commented 5 months ago

Unfortunately is not easy detect, so xserver is not installed or doesn't work. I didn't find any environment variables that should to work on modern and old unixes. You can save this option to configure file, and it should to work

gus-sipc commented 5 months ago

I think it should be safe to check for "clip.exe" first, since a ".exe" program should never be available outside a WSL2 environment.

Inside a WSL2 environment, "clip.exe" is the best option because it is provided by the host Windows operating system. The other clipboard programs provided by Linux environments require further configuration (such as X-server installation) to work correctly with Windows clipboard.

If you agree, I can send a PR to check for "clip.exe" first.

okbob commented 5 months ago

so 13. 4. 2024 v 17:49 odesílatel Gus @.***> napsal:

I think it should be safe to check for "clip.exe" first, since a ".exe" program should never be available outside a WSL2 environment.

Inside a WSL2 environment, "clip.exe" is the best option because it is provided by the host Windows operating system. The other clipboard programs provided by Linux environments require further configuration (such as X-server installation) to work correctly with Windows clipboard.

If you agree, I can send a PR to check for "clip.exe" first.

ok

— Reply to this email directly, view it on GitHub https://github.com/okbob/pspg/issues/242#issuecomment-2053684787, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAEFO43FAXTSSURC633NUADY5FHZLAVCNFSM6AAAAABF62ZQLCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDANJTGY4DINZYG4 . You are receiving this because you commented.Message ID: @.***>