From a2863c451d712e734627e41801037e37cc149632 Mon Sep 17 00:00:00 2001 From: bretello Date: Sat, 10 Feb 2024 12:28:05 +0100 Subject: [PATCH] avoid adding non text/* mime-types to db --- wl-clipboard-history | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/wl-clipboard-history b/wl-clipboard-history index f63541d..0bb86b2 100755 --- a/wl-clipboard-history +++ b/wl-clipboard-history @@ -16,12 +16,12 @@ if [ ! -f "$clipboard_file" ]; then END;" fi - listen () { + echo "$(basename $0) watching for clipboard changes" wl-paste -w wl-clipboard-history } -helpusage () { +helpusage() { echo "Usage: $(basename $0) OPTION [ARG]" echo "" echo "Without any arguments the command will insert contents of stdin in the database" @@ -30,15 +30,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