Skip to content

Instantly share code, notes, and snippets.

@MrYakobo
Created December 8, 2022 09:46
Show Gist options
  • Save MrYakobo/096ab9ba0ba4da19a318feeb242bedc8 to your computer and use it in GitHub Desktop.
Save MrYakobo/096ab9ba0ba4da19a318feeb242bedc8 to your computer and use it in GitHub Desktop.
xclip and xsel alternative, for non-epel rpm distros for example
#!/usr/bin/env python3
# takes text on stdin and stores it in the clipboard
# depends on gtk (i.e. a gnome desktop or something alike)
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk, Gdk
import fileinput
text = "".join(fileinput.input()).rstrip('\n')
clipboard = Gtk.Clipboard.get(Gdk.SELECTION_CLIPBOARD)
clipboard.set_text(text, -1)
clipboard.store()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment