aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/dot_config/waybar/executable_clip-picker.sh
blob: d7f5b61d403e29bb0665596e29af9ac735eee4b2 (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
#!/bin/sh
# Clipboard picker on top of cliphist + wofi (vim-nav, hide-search,
# Alt-d to delete the highlighted entry).
#
# Modes:
#   pick    Enter pastes (cliphist decode | wl-copy)
#   delete  Enter deletes (cliphist delete)
#
# Alt-d in pick mode deletes the highlighted entry without pasting.

set -u

mode=${1:-pick}
style=$HOME/.config/wofi/style.css

set +e
selection=$(
  cliphist list |
    wofi --dmenu --hide-search --prompt Clip \
      --define key_custom_0=Alt-d \
      ${style:+--style "$style"}
)
rc=$?
set -e

[ -z "$selection" ] && exit 0

case "$mode:$rc" in
  pick:0) printf '%s' "$selection" | cliphist decode | wl-copy ;;
  pick:10) printf '%s' "$selection" | cliphist delete ;;
  delete:0 | delete:10) printf '%s' "$selection" | cliphist delete ;;
esac