Skip to content

Instantly share code, notes, and snippets.

@coderofsalvation
Last active November 17, 2023 18:17
Show Gist options
  • Save coderofsalvation/7ff980326e9f75261eee8f8e0896ac3b to your computer and use it in GitHub Desktop.
Save coderofsalvation/7ff980326e9f75261eee8f8e0896ac3b to your computer and use it in GitHub Desktop.
xclip for mac & linux & vim

In action

$ cat ~/projects/foo/somefile.js | xclip
(paste into browser)

$ cat ~/projects/foo/somefile.js | xclipmd
(paste into markdowncompatible website like slackchat etc)

or in console vim, do a visual selection and then press : and type .! xclipmd:

(and paste into slack etc)

Install

$ cd ~/bin
$ wget "https://gist.github.com/coderofsalvation/7ff980326e9f75261eee8f8e0896ac3b/raw/1353c3e57598c1ad6c3b44359d9c8f79a5a6433b/xclip"
$ wget "https://gist.github.com/coderofsalvation/7ff980326e9f75261eee8f8e0896ac3b/raw/68c86602127e14adb58b2fd248608af2df878fae/xclipmd"
$ chmod 755 xclip xclipmd
#!/bin/bash
if [[ "$(uname)" =~ Darwin ]]; then
cat - | pbcopy
else
cat - | xclip
fi
#!/bin/bash
{
echo '```'
cat -
echo '```'
} | xclip
@dotnetCarpenter
Copy link

Hmm... a little elaborate. I just do echo "alias clip='pbcopy'" >> ~/.bash_profile && . ~/.bash_profile once on a mac and the I can use cat whatever.txt | clip to copy text from the terminal to the clip-board, always.

clip works the same on Windows for parity and less typing...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment