nix

configuration files that power my machines
Log | Files | Refs | README | LICENSE

nota (636B)


      1 #!/usr/bin/env bash
      2 
      3 set -euo pipefail
      4 
      5 notebook=${NOTA_NOTEBOOK:-notes}
      6 nb_dir=${NB_DIR:-"$HOME/.nb"}
      7 dir=$nb_dir/$notebook
      8 : "${NOTA_READ_ONLY=0}"
      9 
     10 case ${1:-} in
     11 git)
     12 	shift
     13 	exec nb "$notebook:git" "$@"
     14 	;;
     15 ls)
     16 	exec nb "$notebook:list"
     17 	;;
     18 esac
     19 
     20 unsanitised_name=${1:-today}
     21 case $unsanitised_name in
     22 *' days ago' | yesterday | tomorrow | today)
     23 	unsanitised_name=$(date -d "$unsanitised_name" +%F)
     24 	;;
     25 esac
     26 
     27 name=${unsanitised_name//\//_}
     28 file=$name.org
     29 
     30 if ((NOTA_READ_ONLY)); then
     31 	exec cat -- "$dir/$file"
     32 fi
     33 
     34 if [[ -e "$dir/$file" ]]; then
     35 	exec nb "$notebook:edit" "$file"
     36 else
     37 	exec nb "$notebook:add" --filename "$file"
     38 fi