Skip to content

Commit

Permalink
avoid adding non text/* mime-types to db
Browse files Browse the repository at this point in the history
  • Loading branch information
bretello committed Feb 10, 2024
1 parent 14f936e commit 4ebb718
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions wl-clipboard-history
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ fi


listen () {
echo "$(basename $0) watching for clipboard changes"
wl-paste -w wl-clipboard-history
}

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

mime_type () {
file --mime-type - | sed -E 's|.*: (.*)|\1|'
}

if [ $# = 0 ]; then
contents="$(< /dev/stdin sed "s/'/''/g")"
if [ "$contents" = "" ]; then
helpusage
exit 1
else
query "INSERT INTO c (contents) VALUES ('${contents}');"
exit 0
fi

mime_type="$(echo "${contents}" | mime_type)"
case ${mime_type} in
text/*)
query "INSERT INTO c (contents) VALUES ('${contents}');"
;;
*)
echo "Got mime type ${mime_type}, not inserting."
;;
esac
exit 0
fi


Expand Down

0 comments on commit 4ebb718

Please sign in to comment.