#!/bin/sh set -e exec 2>&1 SEL="../selection" # "xsel --nodetach --input" with an empty input will still exit immediately, # so we need to make sure the selection never is empty: [ -s "$SEL" ] || echo >| "$SEL" xsel --nodetach --logfile /dev/stdout --"$(basename "`pwd`")" \ --input < "$SEL" # something else grabbed the selection. pull it over here: sleep 0.2 xsel --nodetach --logfile /dev/stdout --"$(basename "`pwd`")" \ --output > "$SEL".new # see above: [ -s "$SEL" ] || echo >| "$SEL" mv "$SEL".new "$SEL" sv term ../primary ../secondary ../clipboard