Skip to content

Instantly share code, notes, and snippets.

@zQueal
Created August 3, 2014 07:12
Show Gist options
  • Save zQueal/d7af2a323182e92258da to your computer and use it in GitHub Desktop.
Save zQueal/d7af2a323182e92258da to your computer and use it in GitHub Desktop.
Handy script to help make xclip really simple.
#!/bin/bash
if [[ -t 0  && -z "$1" ]]; then 
    # output contents of clipboard
    xclip -out -selection clipboard || exit 1
elif [[ -n "$1" ]]; then
    # copy file contents to clipboard
    xclip -in -selection clipboard < "$1" || exit 1
else
    # copy stdin to clipboard
    xclip -in -selection clipboard <&0 || exit 1
fi

#Usage

Print contents of the clipboard $ clip

Save clipboard to file $ clip > foo.txt

Pipe output to the clipboard: $ dmesg | tail -n 50 | clip $ cat /proc/cpuinfo | clip

Copy file contents to clipboard $ clip /path/to/some/file.txt

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