├── nota-todo-reminder ├── README.md └── nota /nota-todo-reminder: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | output=$( 4 | # Mediocre escaping for notify-send 5 | NOTA_READ_ONLY=1 nota todo | 6 | sed -e 's//\>/g' -e 's/&/\&/g' 7 | ) 8 | 9 | if [ "$output" ]; then 10 | notify-send -- "You still have items on today's TODO list" "$output" 11 | fi 12 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | `nota` is a simple tool to make and organise notes, using git to keep history, 2 | and your favourite editor for editing. 3 | 4 | You can enable GPG support by doing the following: 5 | 6 | 1. Adding `GPG=1` to `$XDG_CONFIG_HOME/nota`, if `$XDG_CONFIG_HOME` is set, or 7 | `~/.config/nota` if it isn't. You can set this as an environment variable 8 | instead, if you prefer. 9 | 2. Having your editor transparently open gpg files. For example, in vim, you 10 | can use [vim-gnupg][]. You can also set a different `PGP_EDITOR`. 11 | 12 | You can also use read-only mode (which will just display the contents of the 13 | note) using `NOTA_READ_ONLY=1`. 14 | 15 | My primary motivation for making this was that I used [iDoneThis][] for a long 16 | time, but now I need to store sensitive entries that should not leave my local 17 | computer. 18 | 19 | [iDoneThis]: https://idonethis.com/ 20 | [git]: http://git-scm.com/ 21 | [vim-gnupg]: https://github.com/jamessan/vim-gnupg 22 | 23 | ## Usage 24 | 25 | # Edit today's entry (in format YYYY-MM-DD) 26 | nota 27 | 28 | # Edit the entry from yesterday/today/4 days ago 29 | nota (yesterday|today|'4 days ago') 30 | 31 | # Edit the entry for Dec 1 2014 32 | nota 2014-12-01 33 | 34 | # Edit an entry called "foo" 35 | nota foo 36 | 37 | # Set up git to push somewhere if you want it 38 | # You can issue arbitrary git commands using `nota git` 39 | nota git remote add origin 40 | 41 | # nota-todo-reminder 42 | 43 | nota-todo-reminder is a small script calling `notify-send` that outputs the 44 | contents of the nota entry called "todo" if it still contains anything. This 45 | allows you to use nota to remind you of todo entries using a systemd timer, 46 | cron script, or similar. Create a note called "todo" and run it to see how it 47 | works. 48 | -------------------------------------------------------------------------------- /nota: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | shopt -s nullglob 4 | 5 | config=${XDG_CONFIG_HOME:-"$HOME/.config"}/nota 6 | [[ -f "$config" ]] && . "$config" 7 | 8 | data_base_dir=${XDG_DATA_HOME:-"$HOME/.local/share"} 9 | data_dir=$data_base_dir/nota 10 | 11 | mkdir -p "$data_dir" 12 | cd -- "$data_dir" || exit 13 | 14 | : "${NOTA_READ_ONLY=0}" 15 | : "${GPG=0}" 16 | 17 | editor=${EDITOR:-${VISUAL:-vi}} 18 | (( GPG )) && editor=${PGP_EDITOR:-"$editor"} 19 | 20 | if (( NOTA_READ_ONLY )); then 21 | # The linter is wrong here, we don't want to do $(cat). 22 | # shellcheck disable=SC2209 23 | editor=cat 24 | (( GPG )) && editor='gpg -q -d' 25 | fi 26 | 27 | unsanitised_basename=${1:-"$(date +%F)"} 28 | 29 | case $unsanitised_basename in 30 | git|ls) exec "$@" ;; 31 | *' days ago'|yesterday|tomorrow|today) 32 | unsanitised_basename=$(date -d "$unsanitised_basename" +%F) 33 | ;; 34 | esac 35 | 36 | basename=${unsanitised_basename//\//_} 37 | file=$data_dir/$basename 38 | (( GPG )) && file=$file.gpg 39 | 40 | lock_base="$file.lock" 41 | lock="$lock_base.$$" 42 | 43 | if ! (( NOTA_READ_ONLY )); then 44 | for existing_lock_file in "$lock_base".*; do 45 | pid=${existing_lock_file##*.} 46 | if [[ -d "/proc/$pid" ]]; then 47 | printf 'Refusing to open %s as it is locked\n' "$file" >&2 48 | exit 6 49 | else 50 | printf 'Removing stale lock %s\n' "$existing_lock_file" >&2 51 | rmdir -- "$existing_lock_file" 52 | fi 53 | done 54 | 55 | trap 'rmdir -- "$lock"' EXIT 56 | mkdir -- "$lock" 57 | fi 58 | 59 | $editor -- "$file" 60 | 61 | (( NOTA_READ_ONLY )) && exit 0 62 | 63 | if ! [[ -f "$file" ]]; then 64 | printf 'Not committing as %s is missing\n' "$unsanitised_basename" >&2 65 | exit 5 66 | fi 67 | 68 | git init 69 | git add "$file" 70 | rmdir -- "$lock" 71 | trap - EXIT 72 | git commit -m "Updated $unsanitised_basename" 73 | --------------------------------------------------------------------------------