summaryrefslogtreecommitdiff
path: root/newnote
blob: da68221f35a75aaebf9f6fafc13460c9a37ca410 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#!/bin/sh

dir="$OBSIDIAN_HOME"

newnote() {
	file="$dir/$1.md"
	[ -f "$file" ] && {
		echo "Note with the same name already exists, exiting" >&2
		exit 1
	}
	touch "$file" && "$EDITOR" +2 "$file"
	if [ "$(wc -l "$file" | awk '{print $1}')" -lt 2 ]; then
		rm -f "$file"
	fi
}

[ "$#" -ne 1 ] && {
	echo "Usage: newnote <note-name>" >&2
	exit 1
}

newnote "$1"
exit 0