#!/bin/bash # mg - minion gather # Creates a new file $HOME/Journal/YYYY/MM-topic.md with all contents from all matches for all terms # Optionally include a second search term year=`date +%Y` # File to gather all content into topic=$1 if [ ! -n "$1" ]; then echo "A topic to gather is required." exit 1 fi fname=$(printf "$HOME/Journal/$year/%02d-$topic.md" $(date +%m)) archive="$HOME/Journal/archive-$year/" # Files to gather files=$(find $HOME/Journal/$year -type f -iname "*$1*\.md") if [ -n "$files" ]; then echo "Will merge $files into $fname" else echo "Nothing to gather for $topic" fi # optional - more files to gather if [ -n "$2" ]; then more_files=$(find $HOME/Journal/$year -type f -iname "*$2*\.md") fi if [ -n "$more_files" ]; then echo "Will merge $more_files into $fname" else echo "Nothing to gather for $2" fi echo "" read -n1 -p "Continue? [y,N]" input echo "" if [[ ! $input == "Y" && ! $input == "y" ]]; then echo "Aborted by user" exit 1 fi echo "Huzzah!" cat $files >> $fname.gathered mkdir -p $archive mv $files $archive if [ -n "$more_files" ]; then cat $more_files >> $fname.gathered mv $more_files $archive fi mv $fname.gathered $fname if [ -z ${EDITOR} ]; then echo "EDITOR unset, defaulting to Nano" export EDITOR=nano fi $EDITOR $fname