Created
July 25, 2020 01:32
-
-
Save vifon/a0c9c811e79e6d6ef580a04ac6d5ea57 to your computer and use it in GitHub Desktop.
Print to stdout each new X11 selection value separated by a single newline
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Print to stdout each new X11 selection value. By default operates | |
# on "xsel -b". Any passed arguments are used instead of | |
# "-b" verbatim. | |
set -o errexit -o nounset -o pipefail | |
# Set argv to -b (operating on the CLIPBOARD selection) if | |
# not specified. | |
set -- "${@:--b}" | |
# Take control of the selection and wait until some other program | |
# takes it back, changing its value. | |
while xsel -i "$@" -n <<< '' > /dev/null; do | |
# Print the new selection value. $(…) is used to strip the | |
# trailing newlines, printf is used for adding exactly one | |
# newline afterwards. | |
printf '%s\n' "$(xsel "$@" -o)" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment