blob: ee1d2e7b9d17fc5c4c2c27e579bfe5baad6ffdf8 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
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
|