#!/usr/bin/env python3 """ clipmerge.py - merge X11 clipboard and primary selection """ from sh import xsel, clipnotify import argh def get_selections(): c = xsel('-o', '--clipboard') p = xsel('-o', '--primary') return c, p def clipmerge(): c1, p1 = get_selections() while clipnotify() is not None: c2, p2 = get_selections() if c2 != c1: print(c2) xsel('-i', '--primary', _in=c2) c1 = p1 = c2 elif p2 != p1: print(p2) xsel('-i', '--clipboard', _in=p2) c1 = p1 = p2 if __name__ == '__main__': argh.dispatch_command(clipmerge)