-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathns
More file actions
executable file
·40 lines (32 loc) · 1.05 KB
/
ns
File metadata and controls
executable file
·40 lines (32 loc) · 1.05 KB
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
#!/usr/bin/env bash
# ns is a companion script to the notes command
# ns stands for notes-sed
# and is used to print out text in the notes files between two patterns
#
# so for instance, if I edited the current notes file by just doing $ notes (without any arguments)
# I could add a bunch of text between two labels, like for instance:
# BASH_TIPS
# some amount of text on as many lines as you want
# ...
# END_BASH_TIPS
#
# I could then do the $ ns bash_tips end_bash_tips
# (and all the text in between would then print out)
# (sort of like grep on steroids!)
#
# Implementation:
# to account for the very real possibility that there could be more than one of either of the patterns,
# this script first finds the very first line of the first argument
# and the very last line of the second argument
if [ -z "$1" ]; then
echo "usage: ns pattern1 pattern2"
exit 0
fi
p1="$1"
p2="$2"
tmpf=$(mktemp file.XXX)
notes -a > $tmpf
l1=$(grep -ni "$p1" $tmpf | head -1 | cut -d: -f1)
l2=$(grep -ni "$p2" $tmpf | tail -1 | cut -d: -f1)
sed -n "${l1},${l2}p" $tmpf
rm $tmpf