From 14f936e0fe5236669a637e09005d9688699e78a4 Mon Sep 17 00:00:00 2001 From: bretello Date: Fri, 9 Feb 2024 14:53:21 +0100 Subject: [PATCH 1/2] only show command name in usage help --- wl-clipboard-history | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wl-clipboard-history b/wl-clipboard-history index 8db1ad9..f63541d 100755 --- a/wl-clipboard-history +++ b/wl-clipboard-history @@ -22,7 +22,7 @@ listen () { } helpusage () { - echo "Usage: $0 OPTION [ARG]" + echo "Usage: $(basename $0) OPTION [ARG]" echo "" echo "Without any arguments the command will insert contents of stdin in the database" echo " -t Track clipboard changes" From 4ebb718c41bbc3322dd4f2114c14c879cbb3338d Mon Sep 17 00:00:00 2001 From: bretello Date: Sat, 10 Feb 2024 12:28:05 +0100 Subject: [PATCH 2/2] avoid adding non text/* mime-types to db --- wl-clipboard-history | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/wl-clipboard-history b/wl-clipboard-history index f63541d..6993c0d 100755 --- a/wl-clipboard-history +++ b/wl-clipboard-history @@ -18,6 +18,7 @@ fi listen () { + echo "$(basename $0) watching for clipboard changes" wl-paste -w wl-clipboard-history } @@ -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