-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathdmenu_cliphist
30 lines (23 loc) · 1.14 KB
/
dmenu_cliphist
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
#!/usr/bin/env bash
histfile="$HOME/.cache/cliphist"
placeholder="<NEWLINE>"
highlight() {
clip=$(xclip -o -selection primary | xclip -i -f -selection clipboard 2>/dev/null) ;}
output() {
clip=$(xclip -i -f -selection clipboard 2>/dev/null) ;}
write() {
[ -f "$histfile" ] || notify-send "Creating $histfile"; touch $histfile
[ -z "$clip" ] && exit 0
multiline=$(echo "$clip" | sed ':a;N;$!ba;s/\n/'"$placeholder"'/g')
grep -Fxq "$multiline" "$histfile" || echo "$multiline" >> "$histfile"
notification=$(echo \"$multiline\") ;}
sel() {
selection=$(tac "$histfile" | dmenu -b -l 5 -i -p "Clipboard history:")
[ -n "$selection" ] && echo "$selection" | sed "s/$placeholder/\n/g" | xclip -i -selection clipboard && notification="Copied to clipboard!" ;}
case "$1" in
add) highlight && write ;;
out) output && write ;;
sel) sel ;;
*) printf "$0 | File: $histfile\n\nadd - copies primary selection to clipboard, and adds to history file\nout - pipe commands to copy output to clipboard, and add to history file\nsel - select from history file with dmenu and recopy!\n" ; exit 0 ;;
esac
notify-send -h string:fgcolor:#2e3440 "$notification"