gen_todo.sh 705 B

1234567891011121314151617181920212223242526272829303132333435
  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. # Quit if any command produces an error.
  9. set -e
  10. # Check the positional arguments, assign defaults or prompt the user.
  11. if [ $# -lt 2 ];
  12. then
  13. read -p "Priority (ex: 0, 1, 2 or 3):"
  14. if [ -z $REPLY ]
  15. then
  16. PRIORITY="?"
  17. else
  18. PRIORITY=$REPLY
  19. fi
  20. read -p "Description (ex: 'Implement this.'):"
  21. TODO_TEXT=$REPLY
  22. else
  23. PRIORITY=$1
  24. TODO_TEXT=$2
  25. fi
  26. # Build the TODO string.
  27. TIME=`date +%s.%N`
  28. SHASUM=`echo $TIME | shasum`
  29. TODO_ID=${SHASUM:0:6}
  30. TODO_STR="TODO(P$PRIORITY-$TODO_ID): $TODO_TEXT"
  31. echo $TODO_STR