nix

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

todomenu (969B)


      1 #!/bin/bash
      2 
      3 TODO_FILE="$HOME/.nb/notes/todo.txt"
      4 
      5 [ ! -f "$TODO_FILE" ] && exit 1
      6 
      7 selected=$(awk '{
      8     if (/^[0-9]{4}-[0-9]{2}-[0-9]{2}/) {
      9         date = substr($0, 1, 10)
     10         getline
     11         if (/^todo:/) {
     12             match($0, /^todo: (.*)/, arr)
     13             printf "%s\n", arr[1]
     14         }
     15     }
     16 }' "$TODO_FILE" | dmenu "$@")
     17 
     18 [ -z "$selected" ] && exit 0
     19 
     20 task="$selected"
     21 
     22 if ! grep -q "^todo: $task$" "$TODO_FILE"; then
     23 	tmp=$(mktemp)
     24 	printf "%s\ntodo: %s\n\n" "$(date --rfc-3339=s)" "$task" > "$tmp"
     25 	cat "$TODO_FILE" >> "$tmp"
     26 	mv "$tmp" "$TODO_FILE"
     27 else
     28 	action=$(printf "copy to clipboard\nmark as done\nopen in firefox" | dmenu -p "$task" "$@")
     29 	case "$action" in
     30 	"copy to clipboard")
     31 		echo "$task" | wl-copy
     32 		;;
     33 	"mark as done")
     34 		offset=$(grep -bo "^todo: $task$" "$TODO_FILE" | head -1 | cut -d: -f1)
     35 		printf 'done:' | dd of="$TODO_FILE" bs=1 seek="$offset" conv=notrunc 2>/dev/null
     36 		;;
     37 	"open in firefox")
     38 		firefox "$task"
     39 		;;
     40 	esac
     41 fi