-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnote
More file actions
executable file
·37 lines (30 loc) · 894 Bytes
/
Copy pathnote
File metadata and controls
executable file
·37 lines (30 loc) · 894 Bytes
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
#!/bin/bash
# Append a timestamped note to ~/notes.md
# Usage: note "your thought here"
# note (opens notes in $EDITOR)
# note --list / -l [N] (print last N notes, default 10)
NOTES_FILE="${NOTES_FILE:-$HOME/notes.md}"
if [ ! -f "$NOTES_FILE" ]; then
echo "# Notes" > "$NOTES_FILE"
echo "" >> "$NOTES_FILE"
fi
if [ $# -eq 0 ]; then
# Unquoted so values like EDITOR="code --wait" still work.
${EDITOR:-vim} "$NOTES_FILE"
exit 0
fi
if [ "$1" = "--list" ] || [ "$1" = "-l" ]; then
count="${2:-10}"
if ! [[ "$count" =~ ^[0-9]+$ ]] || [ "$count" -eq 0 ]; then
echo "Error: note -l expects a positive number."
exit 1
fi
echo "Last $count notes:"
echo "---"
grep "^- " "$NOTES_FILE" | tail -n "$count"
exit 0
fi
timestamp=$(date "+%Y-%m-%d %H:%M")
entry="- [$timestamp] $*"
echo "$entry" >> "$NOTES_FILE"
echo "Noted: $*"