-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjot
More file actions
executable file
·71 lines (62 loc) · 1.77 KB
/
Copy pathjot
File metadata and controls
executable file
·71 lines (62 loc) · 1.77 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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/bin/bash
# jot: to write or mark down quickly or briefly
jotsPath=~/jots
usage() {
if [ "$#" -gt 0 ]; then
usage="$usage$*\n"
else
echo -e "$usage" | column -t -s:
fi
}
usage "jot id: generate new jot ID"
jot_id() {
date +'%Y-%m-%d-%H%M'
}
usage "jot ref: generate new ref"
usage "jot ref list [<search>]: list refs"
jot_ref() {
if [[ "$1" =~ l|list ]]; then
for f in [0-9-]*; do
# Extract refs from first line of all files (removing @)
for t in $(sed -n -E '/(^|[[:space:]])@([#[:alnum:]_]+)/s/@//gp' $f); do
if [ -n "$2" ]; then
if [ "$2" == "--raw" ]; then
echo "$f:$t"
elif [ "$2" == "$t" ]; then
echo "$f" # files that use this ref
elif [ "$2" == "$f" ]; then
echo "$t" # refs used in this file
fi
else
echo "$t" # all refs
fi
done
done | sort -u
else
printf '@%x\n' "$(date +'%s')"
fi
}
usage "jot ctags: generate ctags index file"
jot_ctags() {
for pair in $(jot_ref list --raw); do
IFS=: read -r f t <<< $pair
echo -e "$t\t$f\t/@$t/;\"\tref"
done > "$jotsPath/tags"
}
# Other commands
usage "jot lf: browse jots in lf"
usage "jot open: open all jots in vim"
usage "jot path: print location of jots"
usage "jot [new]: create new jot"
# Enables us to use relative paths
cd "$jotsPath" || exit 1
case "$1" in
p|path) echo "$jotsPath" ;;
l|lf) lf ;;
i|id) jot_id ;;
r|ref) shift; jot_ref "$@" ;;
c|ctags) jot_ctags ;;
o|open) exec vim [0-9]* ;;
n|new|'') exec vim "$(jot_id)" ;;
*) usage ;;
esac