aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Lemon <chaffinach+git@protonmail.ch>2022-01-11 15:57:18 +0000
committerMatthew Lemon <chaffinach+git@protonmail.ch>2022-01-11 15:57:18 +0000
commitd96e0d75dfdf1601666348fe79b194253e2a0477 (patch)
tree779d9613893f6811c88981972a81506ceb4968a1
parent79908d0f06a13adb62ed11b8935741cbee5d396b (diff)
added grepjournal script - search for term in journal/ and get it back sorted by date
-rwxr-xr-xgrepjournal33
1 files changed, 33 insertions, 0 deletions
diff --git a/grepjournal b/grepjournal
new file mode 100755
index 0000000..012f857
--- /dev/null
+++ b/grepjournal
@@ -0,0 +1,33 @@
+#!/bin/bash
+
+# Search ~/Notes/journal for a term and return as a markdown list sorted by date.
+
+# Automatic cleanup
+trap 'rm -f "$tmpfile"' EXIT
+tmpfile=$(mktemp) || exit 1
+
+# very bad way to check the params passed in...
+[[ -z "$2" ]] && [[ -n "$1" ]] && searchterm="$1"
+[[ -n "$2" ]] && [[ -n "$1" ]] && searchterm="$1" && flag="$2"
+
+# some confirmatory echoing
+echo "Search term: $searchterm"
+[[ -v flag ]] && echo "Flag: $flag"
+
+if [[ $flag != "-i" ]]; then
+ flag=""
+fi
+
+# do the business, starting with using grep to get the pertinent lines
+echo -e "$(grep -R $flag "$searchterm" /home/"$USER"/Notes/journal/)" > "$tmpfile"
+
+# more confirmatory text
+echo Command: 'grep -R $flag "$searchterm" /home/"$USER"/Notes/journal/'
+echo ""
+
+# subsitute to get the right format using sed
+sed -r -i 's/\/home\/lemon\/Notes\/journal\/([[:digit:]]*-[[:digit:]]*-[[:digit:]]*)\.md:-[[:blank:]](.*)/* \1 \2/' "$tmpfile"
+
+# output
+cat "$tmpfile" | sort
+