Skip to content

Commit a2863c4

Browse files
committed
avoid adding non text/* mime-types to db
1 parent bb80064 commit a2863c4

1 file changed

Lines changed: 17 additions & 5 deletions

File tree

wl-clipboard-history

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ if [ ! -f "$clipboard_file" ]; then
1616
END;"
1717
fi
1818

19-
2019
listen () {
20+
echo "$(basename $0) watching for clipboard changes"
2121
wl-paste -w wl-clipboard-history
2222
}
2323

24-
helpusage () {
24+
helpusage() {
2525
echo "Usage: $(basename $0) OPTION [ARG]"
2626
echo ""
2727
echo "Without any arguments the command will insert contents of stdin in the database"
@@ -30,15 +30,27 @@ helpusage () {
3030
echo " -p [INDEX] Print clipboard entry at INDEX (defaults to the last entry)"
3131
}
3232

33+
mime_type() {
34+
file --mime-type - | sed -E 's|.*: (.*)|\1|'
35+
}
36+
3337
if [ $# = 0 ]; then
3438
contents="$(< /dev/stdin sed "s/'/''/g")"
3539
if [ "$contents" = "" ]; then
3640
helpusage
3741
exit 1
38-
else
39-
query "INSERT INTO c (contents) VALUES ('${contents}');"
40-
exit 0
4142
fi
43+
44+
mime_type="$(echo "${contents}" | mime_type)"
45+
case ${mime_type} in
46+
text/*)
47+
query "INSERT INTO c (contents) VALUES ('${contents}');"
48+
;;
49+
*)
50+
echo "Got mime type ${mime_type}, not inserting."
51+
;;
52+
esac
53+
exit 0
4254
fi
4355

4456

0 commit comments

Comments
 (0)