]> apps.delaporte.us Git - minion.git/blob - bin/mg
Fix for bash octal
[minion.git] / bin / mg
1 #!/bin/bash
2 # mg - minion gather
3 # Creates a new file $HOME/Journal/YYYY/MM-topic.md with all contents from all matches for all terms
4 # Optionally include a second search term
5
6 year=`date +%Y`
7 month=`date +%m`
8 # File to gather all content into
9 topic=$1
10 if [ ! -n "$1" ]; then
11 echo "A topic to gather is required."
12 exit 1
13 fi
14
15 mkdir -p "$HOME/Journal/$year"
16 fname="$HOME/Journal/$year/$month-$topic.md"
17 archive="$HOME/Journal/archive-$year/"
18
19 # Files to gather
20 files=$(find $HOME/Journal/$year -type f -iname "*$1*\.md")
21 if [ -n "$files" ]; then
22 echo "Will merge $files into $fname"
23 else
24 echo "Nothing to gather for $topic"
25 fi
26
27 # optional - more files to gather
28 if [ -n "$2" ]; then
29 more_files=$(find $HOME/Journal/$year -type f -iname "*$2*\.md")
30 fi
31 if [ -n "$more_files" ]; then
32 echo "Will merge $more_files into $fname"
33 else
34 echo "No second keyword."
35 fi
36
37 echo ""
38 read -n1 -p "Continue? [y,N]" input
39 echo ""
40 if [[ ! $input == "Y" && ! $input == "y" ]]; then
41 echo "Aborted by user"
42 exit 1
43 fi
44
45 for f in $files; do
46 echo "Gathering $f into $fname"
47 cat "$f" >> "$fname.gathered"
48 done
49
50 mkdir -p $archive
51 mv $files $archive
52
53 if [ -n "$more_files" ]; then
54
55 for f in $more_files; do
56 echo "Gathering $f into $fname"
57 cat "$f" >> "$fname.gathered"
58 done
59
60 mv $more_files $archive
61 fi
62
63 mv $fname.gathered $fname
64
65 if [ -z ${EDITOR} ]; then
66 echo "EDITOR unset, defaulting to Nano"
67 export EDITOR=nano
68 fi
69 $EDITOR $fname
70