blob: cd5c928590cb9168d1ae647d398e5dd382c244f1 (
plain)
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
|
#!/bin/sh
# Display Clipboard Length
DICL_LEN=48
tmp="/tmp/dmclip"
NotImage () {
echo -n "" | dmenu -p "NOT AN IMAGE"
exit
}
selection="$(echo "primary\nclipboard\nswap" |
dmenu -l 1 -g 3 -p "selection:")"
if [ "$selection" = "swap" ]
then
clipboard="$(xclip -o)"
xclip -o | xclip -sel c
echo -n "$clipboard" | xclip -sel c
exit
elif [ "$selection" = "" ]
then
exit 1
elif [ "$selection" = "primary" ]
then
selection2="clipboard"
else
selection2="primary"
fi
if xclip -sel $selection -o -t TARGETS | grep "image/png"
then
disp_clip="IMAGE"
else
clipboard="$(xclip -out -sel "$selection" -r)"
disp_clip="$(echo -n "$clipboard" |
tr -d '\n' |
cut -c -"$DICL_LEN")"
fi
menu_option="$(echo "save\nload\nimage\nreplace" |
dmenu -l 1 -g 4 -p "'$disp_clip'")"
[ "${menu_option}" ] || exit
case "$menu_option" in
replace)
replace_text="$(echo -n "" |
dmenu -l 0 -p "replace:")"
[ "$replace_text" ] || exit
replace_by_text="$(echo -n "" |
dmenu -l 0 -p "by:")"
[ "$replace_by_text" ] || exit
echo "$clipboard" |
sed "s/$replace_text/$replace_by_text/g" |
xclip -r -sel "$selection"
;;
save)
echo "$clipboard" >> /tmp/tmpclip.txt
;;
load)
choice="$(sort "${tmp}.txt" |
uniq |
dmenu -g 1 -l 5)"
[ "$choice" ] || exit 1
echo -n "$choice" | xclip -sel "$selection"
;;
image)
xclip -o -sel c > "${tmp}.png"
file -bi "${tmp}.png" |
grep "image/png" || NotImage
# sed so that dmenu doesn't skip if one line
tesseract "${tmp}.png" stdout > "$tmp"
sed "1i\ " "$tmp" |
dmenu -l 10 -g 1 -p "PREVIEW:" -l 20 ||
exit
xclip -sel "$selection" -i "$tmp"
;;
esac
|