Andrew Rossignol | bf3095a | 2017-09-25 16:49:35 -0700 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | # |
| 3 | # Generate a TODO with a unique hash and priority level to allow tracking. |
| 4 | # |
| 5 | # Usage: ./gen_todo.sh 2 "Implement this." |
| 6 | # |
| 7 | # Output: TODO(P2-a07e5416): Implement this. |
| 8 | |
| 9 | # Quit if any command produces an error. |
| 10 | set -e |
| 11 | |
| 12 | # Check the positional arguments, assign defaults or prompt the user. |
| 13 | if [ $# -lt 2 ]; |
| 14 | then |
| 15 | read -p "Priority (ex: 0, 1, 2 or 3):" |
| 16 | if [ -z $REPLY ] |
| 17 | then |
| 18 | PRIORITY="?" |
| 19 | else |
| 20 | PRIORITY=$REPLY |
| 21 | fi |
| 22 | |
| 23 | read -p "Description (ex: 'Implement this.'):" |
| 24 | TODO_TEXT=$REPLY |
| 25 | else |
| 26 | PRIORITY=$1 |
| 27 | TODO_TEXT=$2 |
| 28 | fi |
| 29 | |
| 30 | # Build the TODO string. |
| 31 | TIME=`date +%s.%N` |
| 32 | SHASUM=`echo $TIME | shasum` |
| 33 | TODO_ID=${SHASUM:0:6} |
| 34 | TODO_STR="TODO(P$PRIORITY-$TODO_ID): $TODO_TEXT" |
| 35 | echo $TODO_STR |