From 25092fe9b45a56b6c7f4014b164e74fc2164f6d7 Mon Sep 17 00:00:00 2001 From: dmarakom6 Date: Mon, 28 Jun 2021 12:54:38 +0300 Subject: [PATCH] Improve split-char command "notegrep -sc" now checks if the note given actually exists or if there are no matches with your input. --- util/notegrep/sc.sh | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/util/notegrep/sc.sh b/util/notegrep/sc.sh index cf37c62..817abc2 100644 --- a/util/notegrep/sc.sh +++ b/util/notegrep/sc.sh @@ -5,10 +5,26 @@ Released under the "All rights reserved" category. See the RIGHTS.txt file in /docs/github/ for its full text. info -out="$(cat $DEFAULT_PATH/$notename | sed s/$regex/\\n/g | wc -l)" -if [ $out -gt 20 ]; then - cat $DEFAULT_PATH/$notename | sed s/$regex/\\n/g | less -elif [ $out -le 20 ]; then - cat $DEFAULT_PATH/$notename | sed s/$regex/\\n/g +if [ -f $DEFAULT_PATH/$notename ]; then + + if grep -q $regex $DEFAULT_PATH/$notename; then + + out="$(cat $DEFAULT_PATH/$notename | sed s/$regex/\\n/g | wc -l)" + + if [ $out -gt 20 ]; then + cat $DEFAULT_PATH/$notename | sed s/$regex/\\n/g | less + elif [ $out -le 20 ]; then + cat $DEFAULT_PATH/$notename | sed s/$regex/\\n/g + fi + + else + echo "No matches found." + return 0 + + fi + +else + echo "This note doesn't exist." + return 0 fi