Skip to content

Instantly share code, notes, and snippets.

@schoettl
Created February 2, 2019 19:01
Show Gist options
  • Save schoettl/75addb5639308617554bdafeabd1c26f to your computer and use it in GitHub Desktop.
Save schoettl/75addb5639308617554bdafeabd1c26f to your computer and use it in GitHub Desktop.
Copy text to both normal X clipboard and primary selection (middle mouse button)
# Note the -f option for xclip:
echo foo | xclip -f -i -selection clipboard | xclip -i -selection primary
# Short form:
echo foo | xclip -f -selection c | xclip
# Before I discovered xclip -f, I tried this which did not work in my Bash 5:
echo foo | tee >(xclip -i -selection clipboard) | xclip -i -selection primary
# Before that, I used this snippet:
declare tmp
tmp=$(mktemp)
echo foo > "$tmp"
xclip -selection c < "$tmp"
xclip -selection p < "$tmp"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment