Skip to content

Instantly share code, notes, and snippets.

Last active September 13, 2023 14:59
  • Star 12 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
clip: WSL bash script to access the Windows Clipboard (both read and write)
[[ ! -t 1 ]] && powershell.exe Get-Clipboard
[[ ! -t 0 ]] && clip.exe
if [[ -t 1 && -t 0 ]]; then
echo Nothing specified to copy or paste! >&2
exit 1
Copy link

vor0nwe commented Jan 16, 2020

Save this gist to a file called clip somewhere in your $PATH, and make executable with chmod u+x clip.
You can then redirect stuff from and to clip, or pipe to clip.

To sort a bunch of text you've copied:

clip | sort

or plain dump the text on the clipboard into a file:

clip > clipboard.txt

To copy the contents of a file to the clipboard:

clip < file.txt
# or
cat file.txt | clip

Copy link

Exactly what I was looking for. Thanks 😊.

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