66 lines
1.2 KiB
Bash
66 lines
1.2 KiB
Bash
#!/usr/bin/env bash
|
|
|
|
NOTEBOOK_DIR=~/notebook
|
|
|
|
if [[ ! -d "$NOTEBOOK_DIR" ]]; then
|
|
echo "Error: Notebook directory does not exist at $NOTEBOOK_DIR"
|
|
exit 1
|
|
fi
|
|
|
|
cd "$NOTEBOOK_DIR" || exit 1
|
|
|
|
show_help() {
|
|
cat << EOF
|
|
nb - Notebook management tool
|
|
|
|
Usage: nb <command>
|
|
|
|
Commands:
|
|
cd Change directories
|
|
save Commit changes with timestamp
|
|
sync Save, fetch, and push changes
|
|
log Show commit log
|
|
diff Show differences
|
|
status Show diff summary
|
|
todo Add a todo item (or manage todos)
|
|
archive Archive completed todos
|
|
|
|
EOF
|
|
}
|
|
|
|
case "$1" in
|
|
cd)
|
|
exec "$SHELL"
|
|
;;
|
|
save)
|
|
jj diff -r @ --summary | grep -q . && jj commit -m "$(date +"%Y-%m-%dT%H:%M:%S%z")" && jj tug || true
|
|
;;
|
|
sync)
|
|
"$0" save && jj git fetch && jj git push
|
|
;;
|
|
log)
|
|
jj log -r ".."
|
|
;;
|
|
diff)
|
|
jj diff
|
|
;;
|
|
status)
|
|
jj diff -s
|
|
;;
|
|
todo)
|
|
if [[ "$2" == "archive" && -z "$3" ]]; then
|
|
todo_archive todo.xit done.xit
|
|
else
|
|
todo "${@:2}"
|
|
fi
|
|
;;
|
|
"")
|
|
show_help
|
|
;;
|
|
*)
|
|
echo "Error: Unknown command '$1'"
|
|
echo ""
|
|
show_help
|
|
exit 1
|
|
;;
|
|
esac
|