dotfiles/writing/zk/config/sh/alias.d/zk.sh
Marty Oehme a01431609f
zk: Set working dir to wiki for aliases
Instead of finding the notebook at the wikiroot, we directly change the
current working dir to the notebook for the runtime of the zk command.

This has a couple advantages: Any other commands executed will also pick
up the correct directory, and creating notes in a specific directory
also just _works_ by giving a directory in the notes dir even if we are
somewhere else.
2025-03-10 20:22:02 +01:00

35 lines
820 B
Bash

#!/usr/bin/env sh
#
_zk_wiki() {
zk --working-dir="$WIKIROOT" "$@"
}
n() {
if [ $# -eq 0 ]; then
_zk_wiki edit -i
else
_zk_wiki "${@}"
fi
}
# We have a local wiki
if [ -n "${WIKIROOT}" ]; then
# open notes with my vim zettelkasten plugin
# TODO better implementation conditional on zk.nvim & zettelkasten existing
# nvim +'lua pcall(require "zk.commands"') --headless +qa 2>&1 or similar to check - but slow
if command -v nvim >/dev/null 2>&1; then
alias ni='nvim +"lua require \"zk.commands\".get(\"ZkCd\")()" +"edit $WIKIROOT/index.md"'
fi
alias ncd='cd $WIKIROOT'
nn() { # 'new note'
_zk_wiki new "$@"
}
nnl() { # 'new note log'
_zk_wiki log "$@"
}
nnd() { # 'new note draft'
_zk_wiki draft "$@"
}
fi