diff options
| author | Anton Bobov <anton@bobov.name> | 2023-08-05 23:48:19 +0500 |
|---|---|---|
| committer | Anton Bobov <anton@bobov.name> | 2023-08-05 23:48:19 +0500 |
| commit | 7fb714fadb768401b251a7584d76f216acf5943a (patch) | |
| tree | d1f85b5d5e74ac1c45ec4b956e8e851ce9469d6f /clipboard-stream | |
| parent | b25a5b794be7093dbcd556fcab2ebc50bb33e8b2 (diff) | |
Update scripts
Diffstat (limited to 'clipboard-stream')
| -rwxr-xr-x | clipboard-stream | 34 |
1 files changed, 25 insertions, 9 deletions
diff --git a/clipboard-stream b/clipboard-stream index b4c1120..a1f0cdc 100755 --- a/clipboard-stream +++ b/clipboard-stream @@ -1,13 +1,29 @@ #!/bin/bash -set -e - -recent_value=$(xclip -o -selection clipboard) -while true ; do - value=$(xclip -o -selection clipboard) - if [ "$recent_value" != "$value" ] ; then - recent_value=$value - echo $recent_value +set -euo pipefail + +find_clipboard_command() { + if command -v xclip &>/dev/null; then + echo xclip -out -selection clipboard + elif command -v xsel &>/dev/null; then + echo xsel --output --clipboard + else + echo "No clipboard command found" >&2 + exit 1 + fi +} + +main() { + CLIPBOARD_COMMAND=$(find_clipboard_command) + recent_value=$(eval "$CLIPBOARD_COMMAND") + while true; do + value=$(eval "$CLIPBOARD_COMMAND") + if [ "$recent_value" != "$value" ]; then + recent_value=$value + echo "$recent_value" fi sleep 0.1 -done + done +} + +main "$@" |
