Sample Header Ad - 728x90

Linux clipboards, including with WSL consoles

3 votes
2 answers
1543 views
It occurred to me that there are multiple clipboards on any given Linux console: - First is the bash clipboard, this can be invoked by Ctrl-U / K, cut all line before (U) or after (K) cursor into clipboard, or Ctrl-W, to cut the word on the left side of the cursor (is there a corresponding "cut word on right side"?), and then Ctrl-Y to paste somewhere else. - Then we have the X clipboard, which is setup as follows (I don't know where the names pbcopy and pbpaste come from, but I have seen these names dozens of times, so it seems a lot of people use that nomenclature for some reason):
sudo apt install xclip xsel
alias pbcopy='xclip -selection clipboard'      # To use xclip for copy
alias pbpaste='xclip -selection clipboard -o'  # To use xclip for paste
alias pbcopy='xsel --clipboard --input'        # To use xsel for copy
alias pbpaste='xsel --clipboard --output'      # To use xsel for paste
- Then, additionally, if you are on WSL, there is a third clipboard, from Windows, which you can send to quite simply, e.g. echo 123 | clip.exe. To do the reverse, and paste into the WSL console, you can use powershell.exe -noprofile Get-Clipboard > file.txt. It would be be good to completely control how information is sent/retrieved from these various clipboards easily. - I can pipe information into the X clipboard (with xclip and xsel), but I have not found a way to pipe things into the bash buffer; how do we pipe into the bash buffer programmatically? - How can I pipe something into all 4 clipboards (assuming that xclip and xsel are independent?) from one output in single command (I seem to remember that tee can do this, but not certain)? By knowing this, I would then be able to send receive information from any of the 4 clipboards.
echo 123 |
For reference, though does not answer the above. https://stackoverflow.com/questions/5130968/how-can-i-copy-the-output-of-a-command-directly-into-my-clipboard
Asked by YorSubs (661 rep)
Oct 13, 2021, 11:05 AM
Last activity: Oct 14, 2021, 08:22 AM