summaryrefslogtreecommitdiffstatshomepage
path: root/zk/.local/bin/zkf
blob: 12a957a4925888a5064d27551c441b7edb6d01d6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#!/bin/sh

if [ "$#" -eq 0 ]; then
	set -- "$(
		rg '^# (.*)$' "$ZK_NOTEBOOK_DIR" --type=markdown --max-count=1 --vimgrep --replace '$1' \
			--no-line-number --no-column |
			fzf-tmux "$FZF_TMUX_OPTS" -- --tac --print-query -d: --with-nth -1 \
				--bind 'focus:transform-header(echo {1})' \
				--preview-window='right,100,<100(up,75%,border-bottom)' \
				--preview="glow -l -w 100 --style dark {1}" |
			tail -1 |
			cut -d: -f1
	)"
fi

if [ -z "$1" ]; then
	exit 1
elif [ -f "$1" ]; then
	$EDITOR -c "cd $ZK_NOTEBOOK_DIR" "$1"
else
	zk new --title="$1"
fi