]> apps.delaporte.us Git - minion.git/commitdiff
Add minion gather command
authorEdward Delaporte <edward@delaporte.us>
Tue, 23 Jun 2026 22:23:21 +0000 (17:23 -0500)
committerEdward Delaporte <edward@delaporte.us>
Tue, 23 Jun 2026 22:23:21 +0000 (17:23 -0500)
bin/mg [new file with mode: 0755]
bin/mh

diff --git a/bin/mg b/bin/mg
new file mode 100755 (executable)
index 0000000..e803fe6
--- /dev/null
+++ b/bin/mg
@@ -0,0 +1,59 @@
+#!/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
+
diff --git a/bin/mh b/bin/mh
index ffbbce33af04a9e8ca0495ae47c6bd31a9914e39..202606df6e71c56e0483775331d15cdf58ae1d22 100755 (executable)
--- a/bin/mh
+++ b/bin/mh
@@ -16,6 +16,7 @@ echo "mo manager - open files named with 'manager' to edit"
 echo ""
 echo "Advanced Usage:"
 echo ""
+echo "mg - minion gather - gather matching files into a single file"
 echo "mp - minion print - convert matching files to HTML and open in Firefox (requires https://github.com/gomarkdown/markdown)"
 echo "ms - minion spell - open the matching file with 'aspell'"
 echo "mla, moa, etc - minion X all - act as 'ml' and 'mo', but include all previous years of Journal entries"