Skip to content

Commit

Permalink
Ignore empty blocks of notes
Browse files Browse the repository at this point in the history
Signed-off-by: Jan-Christoph Borchardt <hey@jancborchardt.net>
  • Loading branch information
jancborchardt committed Jan 11, 2019
1 parent 58a11d1 commit e102c3c
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions randomblock.sh
Expand Up @@ -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
Expand All @@ -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 ""
Expand Down

0 comments on commit e102c3c

Please sign in to comment.