-
Notifications
You must be signed in to change notification settings - Fork 0
/
nt
executable file
·40 lines (34 loc) · 822 Bytes
/
nt
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
#!/usr/bin/env bash
_NOTES_DIR=$HOME/notes
if [ "${1:-""}" = "--log" ]; then
set-window-title.sh logbook
$EDITOR $_NOTES_DIR/log/$(date +%F).md
exit
fi
while true; do
set-window-title.sh notes
files=$(find $_NOTES_DIR -type f \
! -path "$_NOTES_DIR/.*/*" \
! -path "$_NOTES_DIR/log/*" \
! -name ".*" \
)
file="$(ls -t $files | \
sed "s#$_NOTES_DIR/##" | \
fzf --print-query \
--select-1 \
--preview="cat $_NOTES_DIR/{}" | \
tail -n1 | \
# remove leading new line
xargs echo -n
)"
if [ -z "$file" ]; then
break
fi
file="$_NOTES_DIR/$file"
dir=$(dirname "$file")
if [ ! -d "$dir" ]; then
mkdir -p $dir
fi
set-window-title.sh notes ${file}
$EDITOR $file
done