Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
executable file 50 lines (43 sloc) 1.8 KB
# πŸ’»πŸ”€πŸ—‘οΈ Keep or Sweep for notes!
# Show a random block of text from a notes random notes file
# Simply make executable and click (or run as bash
# Use the current folder for now
# Get a random file, ignoring hidden files
# "tr -d '\0'" gets rid of "command substitution: ignored null byte in input"
RANDOMFILE=$(find "$FOLDER" -not -path '*/\.*' -type f -print0 | shuf -zn1 | tr -d '\0')
# Separate note files to blocks, give out one random block
# Code from
declare -a arr
while read -r line
# If we find an empty line, then we increase the counter (i),
# set the flag (s) to one, and skip to the next line
[[ $line == "" ]] && ((i++)) && s=1 && continue
# If the flag (s) is zero, then we are not in a new line of the block
# so we set the value of the array to be the previous value concatenated
# with the current line
[[ $s == 0 ]] && arr[$i]="${arr[$i]}
$line" || {
# Otherwise we are in the first line of the block, so we set the value
# of the array to the current line, and then we reset the flag (s) to zero
done < "$RANDOMFILE"
# Choose index to be a random number from 0 to the length of the array
# Code from
# Modified to skip empty blocks
while [ "$selectedblock" == "" ]; do
selectedblock=${arr[$RANDOM % ${#arr[@]} ]}
echo ""
echo "$selectedblock"