alias clip="xclip -selection clipboard"
`echo hello | clip` will copy 'hello' to the clipboard, and similarly `ls | clip` will copy a bunch of lines to the clipboard. You might need to install xclip through your package manger (the package is just named xclip on Arch). # Paste clipboard into command.
xsel --clipboard | grep foobar
# Copy into clipboard
grep foobar somefile.txt | xsel --clipboard
# Transform clipboard.
xsel --clipboard | tr A-Z a-z | xsel --clipboard
I find this so useful that I have it aliased to `c`. if [[ "$(uname)" == "Linux" ]]; then
if ! grep -q Microsoft /proc/version; then
alias pbcopy='xsel --clipboard --input'
alias pbpaste='xsel --clipboard --output'
else
alias pbcopy='clip.exe'
alias pbpaste='powershell.exe -command "Get-Clipboard"'
fi
fiThis tool looks great for more involved use cases though I think for most scenarios I’d use it for, using the mouse with iTerm2 with “copy on highlight” might be quicker - can be nice to avoid the mouse though!
Sometimes I need the URL itself, as opposed to actually opening it. I wrote elisp to modify the command that displays the URL the cursor is over within Emacs to also use the above method, but use `pbcopy` to pass the URL onto the Mac clipboard.
But if you run VcXsrv you can use the native Linux clipboard and have it shared between WSL 2 and Windows. This is what I do because then tools like Vim, the pass utility and other command line tools can write to and read from the native Linux clipboard and everything will work out of the box.
If you wanted to reproduce pbcopy / pbpaste in native Linux or WSL 2 you can set up aliases for:
alias pbcopy="xclip -selection clipboard"
alias pbpaste="xclip -o"
And in case you don't already have xclip installed in WSL 2, you can apt-get install xclip or use whatever package manager you have. I can't remember if xclip is installed by default in WSL 2 distros.A video walk through of my current Windows / WSL 2 / etc. dev environment is here: https://nickjanetakis.com/blog/a-linux-dev-environment-on-wi...