4 ms·
On Mac OS, a much less powerful but built in tool is `pbcopy`.
by Hnrobert42 6y ago
On Mac OS, a much less powerful but built in tool is `pbcopy`.
- the_pwner224 6y agoTo replicate pbcoby on X11 systems, add to your bashrc: 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).
- kevincox 6y agoI like `xsel --clipboard` which Does The Right Thing by automatically deciding if it should copy or paste. # 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`.
- opan 6y agoOn Wayland there's wl-clipboard (with wl-copy and wl-paste commands) which works basically the same.
- jonS90 6y agoThis is how I make pbcopy/pbpaste work on both Linux and WSL (Windows Subsystem for Linux). 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 fi
- tomduncalf 6y agoWas going to say this myself. I find myself using it (and it’s counterpart, `pbpaste`) surprisingly frequently. This 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!
- drcursor 6y agoI use that very often. Is there any equivalent on the WSL2 world ?
- eknkc 6y ago“| clip.exe” should work
- drcursor 6y agoThat works outside WSL2, not inside, right?
- nickjj 6y agoclip.exe works to and from WSL 2. 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.
- eknkc 6y agoOh that’s neat. Do you use the x server for just this purpose or do you also run linux gui apps? I’ve been thinking about investing more into it but the high dpi stuff does not work properly.
- nickjj 6y agoI use it just for the clipboard but I used to run Sublime Text through it years ago (using WSL 1). It was really fast and worked great, at least at 2560x1440. A video walk through of my current Windows / WSL 2 / etc. dev environment is here: https://nickjanetakis.com/blog/a-linux-dev-environment-on-windows-with-wsl-2-docker-desktop-and-more https://nickjanetakis.com/blog/a-linux-dev-environment-on-wi...
- ZeroGravitas 6y agoThis tool seems to be more about the selection part, once it knows exactly what you want it passes it onto another clipboard tool, which for the Mac is pbcopy.
- ylee 6y agoI have used VM in Emacs to read my email for more than a quarter century. I run the Emacs session remotely, and open inline URLs locally on the Macbook I `mosh` out of. The remote machine connects to the local one and passes on the URL with `open`. 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.