summaryrefslogtreecommitdiff
path: root/clipboard-stream
blob: a1defc60c4c092909d93b2035adfaff2d9513a68 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/bin/bash

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
}

clipman_settings() {
  xfconf-query -c xfce4-panel -p /plugins/clipman/settings/enable-actions "$@" 2>/dev/null
}

restore_clipman_actions() {
  if [ -n "$1" ]; then
    clipman_settings -s "$1"
  fi
}

main() {
  CLIPMAN_ACTION_STATE=$(clipman_settings || echo)
  trap 'restore_clipman_actions "$CLIPMAN_ACTION_STATE"' EXIT
  clipman_settings -s 'false' >/dev/null || true

  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
}

main "$@"