Skip to content

Commit 4ebb718

Browse files
committed
avoid adding non text/* mime-types to db
1 parent 14f936e commit 4ebb718

1 file changed

Lines changed: 16 additions & 3 deletions

File tree

wl-clipboard-history

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ fi
1818

1919

2020
listen () {
21+
echo "$(basename $0) watching for clipboard changes"
2122
wl-paste -w wl-clipboard-history
2223
}
2324

@@ -30,15 +31,27 @@ helpusage () {
3031
echo " -p [INDEX] Print clipboard entry at INDEX (defaults to the last entry)"
3132
}
3233

34+
mime_type () {
35+
file --mime-type - | sed -E 's|.*: (.*)|\1|'
36+
}
37+
3338
if [ $# = 0 ]; then
3439
contents="$(< /dev/stdin sed "s/'/''/g")"
3540
if [ "$contents" = "" ]; then
3641
helpusage
3742
exit 1
38-
else
39-
query "INSERT INTO c (contents) VALUES ('${contents}');"
40-
exit 0
4143
fi
44+
45+
mime_type="$(echo "${contents}" | mime_type)"
46+
case ${mime_type} in
47+
text/*)
48+
query "INSERT INTO c (contents) VALUES ('${contents}');"
49+
;;
50+
*)
51+
echo "Got mime type ${mime_type}, not inserting."
52+
;;
53+
esac
54+
exit 0
4255
fi
4356

4457

0 commit comments

Comments
 (0)