bin/waybar-clipboard 847 B raw
1
#!/bin/sh
2
3
refresh_waybar() {
4
  pkill -RTMIN+9 -x waybar
5
}
6
7
case "$1" in
8
  status)
9
    count=$(cliphist list 2>/dev/null | wc -l)
10
    printf '{"tooltip":"%s clipboard items"}\n' "$count"
11
    ;;
12
  has-items)
13
    command -v cliphist >/dev/null 2>&1 || exit 1
14
    test "$(cliphist list 2>/dev/null | wc -l)" -gt 0
15
    ;;
16
  copy)
17
    item=$(cliphist list | fuzzel --dmenu --width 100) || exit
18
    test -n "$item" || exit
19
    printf '%s\n' "$item" | cliphist decode | wl-copy || exit
20
    refresh_waybar
21
    ;;
22
  delete)
23
    item=$(cliphist list | fuzzel --dmenu --width 100) || exit
24
    test -n "$item" || exit
25
    printf '%s\n' "$item" | cliphist delete || exit
26
    refresh_waybar
27
    ;;
28
  wipe)
29
    cliphist wipe || exit
30
    refresh_waybar
31
    ;;
32
  *)
33
    echo "usage: waybar-clipboard {status|has-items|copy|delete|wipe}" >&2
34
    exit 2
35
    ;;
36
esac