zk/zk

47 lines
658 B
Bash
Executable File

#!/bin/sh
ZKDIR="$HOME/.local/share/zk/"
COMMANDS='list new'
get_command() {
commands="$1"
input="$2"
for c in $commands; do
if echo "$c" | grep "^$input" >/dev/null; then
echo "$c"
fi
done
}
_zk_isosec() {
date -u +%Y%m%d%H%M%S
}
_zk_list() {
for zettel in "$ZKDIR"/*; do
echo "$(basename "$zettel") | $(head -1 "$zettel")"
done
}
_zk_new() {
filename="$(_zk_isosec)"
touch "$ZKDIR/$filename"
if test -n "$EDITOR"; then
$EDITOR "$ZKDIR/$filename"
else
vi "$ZKDIR/$filename"
fi
}
main() {
subcommand="$(get_commands "$COMMANDS" "$1")"
_zk_"$subcommand"
}
name="$(basename "$0")"
if test "$name" = "zk"; then
main "$@"
fi