Permalink
Browse files

Ignore empty blocks of notes

Signed-off-by: Jan-Christoph Borchardt <hey@jancborchardt.net>
  • Loading branch information...
jancborchardt committed Jan 11, 2019
1 parent 58a11d1 commit e102c3cf910c2cb87762df65d3d567a96421fed5
Showing with 5 additions and 2 deletions.
  1. +5 −2 randomblock.sh
@@ -15,7 +15,6 @@ RANDOMFILE=$(find "$FOLDER" -not -path '*/\.*' -type f -print0 | shuf -zn1 | tr

# Separate note files to blocks, give out one random block
# Code from https://stackoverflow.com/a/18539730
# TODO: Ignore blocks consisting of empty lines
i=1
s=1
declare -a arr
@@ -39,7 +38,11 @@ done < "$RANDOMFILE"

# Choose index to be a random number from 0 to the length of the array
# Code from https://stackoverflow.com/a/2388555
selectedblock=${arr[$RANDOM % ${#arr[@]} ]}
# Modified to skip empty blocks
selectedblock=""
while [ "$selectedblock" == "" ]; do
selectedblock=${arr[$RANDOM % ${#arr[@]} ]}
done

echo "$RANDOMFILE"
echo ""

0 comments on commit e102c3c

Please sign in to comment.