From a398357fb161233c3293b07ab9bd5c17d693cef5 Mon Sep 17 00:00:00 2001 From: BarbUk Date: Mon, 28 Oct 2019 15:07:53 +0400 Subject: [PATCH] Don't write empty $content in tmpfile and return if tmpfile is empty --- snippy | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/snippy b/snippy index 98a6feb..627ff6d 100755 --- a/snippy +++ b/snippy @@ -150,12 +150,19 @@ run() { content="$( bashdown_simple < "${snippets_directory}/${snippet}" )" fi - printf "%s" "$content" > "$tmpfile" + if [ -n "$content" ]; then + printf "%s" "$content" > "$tmpfile" + fi else [[ ${snippet} =~ ^$ ]] ${snippet##*$} 2>/dev/null > "$tmpfile" # execute as bashcommand fi + # if tmpfile is empty at this step, nothing to do. + if [ ! -s "$tmpfile" ]; then + return + fi + # save current clipboard current_clipboard=$(xsel -b) # replace {clipboard} by the clipboard content