shellnotes/util/notegrep/ws.sh

51 lines
1 KiB
Bash
Raw Normal View History

2021-06-29 08:07:20 +02:00
:<<'info'
shellnotes - ws.sh
(C) Dimitris Marakomihelakis
Released under the "All rights reserved" category. See the RIGHTS.txt file
in /docs/github/ for its full text.
info
2021-07-01 16:55:58 +02:00
grepv() { #the command run when input is valid
if [ $(grep -v $regex $DEFAULT_PATH/$notename | wc -l) -ge 20 ]; then
grep -v $regex $DEFAULT_PATH/$notename | less
else
grep -v $regex $DEFAULT_PATH/$notename
fi
}
2021-06-30 18:07:37 +02:00
nomatch() {
echo -n "There are no matches.\nView note anyway?(Y/N): " && read view
case $view in
y | Y | yes | YES | Yes )
2021-07-01 16:55:58 +02:00
if [ $(cat $DEFAULT_PATH/$notename | wc -l) -ge 20 ]; then
less $DEFAULT_PATH/$notename
else
cat $DEFAULT_PATH/$notename
fi
2021-06-30 18:07:37 +02:00
return 0
;;
*)
echo "Cancelled."
return 0
;;
esac
}
2021-06-29 08:07:20 +02:00
if [ -f $DEFAULT_PATH/$notename ]; then
if grep -vq $regex $DEFAULT_PATH/$notename ; then
2021-06-30 18:07:37 +02:00
test "$(cat $DEFAULT_PATH/$notename)" = "$(grep -v $regex $DEFAULT_PATH/$notename)" && nomatch || grepv && return 0
2021-06-29 08:07:20 +02:00
else
echo "Pattern matches the whole file."
return 0
fi
else
echo "This note doesn't exist."
return 0
fi