-
Notifications
You must be signed in to change notification settings - Fork 122
/
find-notes
executable file
·49 lines (41 loc) · 1.33 KB
/
find-notes
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/bin/sh
#
# We use Apple's Spotlight System (via mdfind) to do the initial
# search for particluar files. We then get some context for the
# results by calling grep. The result should work well with Emacs.
INITIAL_LOCATIONS="$HOME/technical $HOME/Notes $HOME/journal $HOME/Dropbox/org
$HOME/personal $HOME/Other/dot-files $HOME/Work/dot-files"
# I run this script on many different machines, which may or may not
# have all of the directories listed above, so let's make sure they
# exist first.
LOCATIONS=""
for DIR in $INITIAL_LOCATIONS
do
if [ -d $DIR ]
then
LOCATIONS="$LOCATIONS -onlyin $DIR"
fi
done
# While mdfind will put the text in any order, grep requires the
# regular expression to be separated by vertical bars:
REGEXP=$(echo "$*" | sed 's/ /\\|/g')
TRIM=$(echo "$HOME" | wc -m)
if [ -e /etc/redhat-release -o -e /etc/lsb-release -o -e /etc/os-release ]
then
CALL="recoll -t -a -b"
else
CALL="mdfind $LOCATIONS -interpret"
fi
$CALL $* | sed 's/^file:\/\///' | while read FILE
do
if echo $FILE | grep -v -q '#'
then
LOC=$(grep -ni -m 1 "$REGEXP" "$FILE" | cut -d: -f1)
NAME=$(echo $FILE | cut -c$TRIM-)
TITLE=$(head -n 1 "$FILE" | sed 's/#+TITLE: //')
echo "~$NAME:$LOC: $TITLE"
grep -C 1 -i -m 3 "$REGEXP" "$FILE"
echo
fi
done
echo "----eot-----"