logo

utils

~/.local/bin tools and git-hooks git clone https://hacktivis.me/git/utils.git

timey-whyme.sh (1773B)


  1. #!/bin/sh
  2. # Copyright 2017-2022 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me>
  3. # SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only
  4. xdd="${XDG_DATA_DIR:-$HOME/.local/share}/timey-whyme"
  5. today="$(date --date=now +%Y-%m-%d)"
  6. later="$(date --date=+7days +%Y-%m-%d)"
  7. headers=true
  8. usage() {
  9. echo "$0"' [t…|c…|h…]
  10. c…: show calendar
  11. t…: show todo
  12. h…: this help'
  13. echo '
  14. Files used:
  15. • '"$xdd"'/calendar.csv
  16. • '"$xdd"'/todo.csv'
  17. echo '
  18. Environment used:
  19. XDG_DATA_DIR (defaults to “~/.local/share”)'
  20. }
  21. die() {
  22. echo "$1"
  23. exit
  24. }
  25. verify_xxd() {
  26. [ -e "${xdd}/${1}" ] || die "Please create the following file, see examples for help: ${xdd}/${1}"
  27. }
  28. todo_gen() {
  29. # (GNU-ism) nowarn: turn off warning: table wider than line width
  30. echo \
  31. '.color 1
  32. .TS
  33. nowarn;
  34. llll.'
  35. $headers && echo \
  36. '.TH
  37. Deadline Nice Description Location
  38. .TB
  39. _'
  40. (
  41. cut -d '#' -f -1 "$xdd/todo.csv" | grep -v '^$'
  42. echo "${today},\m[blue],Now"
  43. echo "${later},\m[],In 7 days"
  44. ) | sort -n | tr ',' ' '
  45. echo '.TE'
  46. }
  47. calendar_gen() {
  48. # (GNU-ism) nowarn: turn off warning: table wider than line width
  49. echo \
  50. '.color 1
  51. .TS
  52. nowarn;
  53. llll.'
  54. $headers && echo \
  55. '.TH
  56. Start End Description Location
  57. .TB
  58. _'
  59. (
  60. cut -d '#' -f -1 "$xdd/calendar.csv" | grep -v '^$'
  61. echo "${today},\m[blue],Now"
  62. echo "${later},\m[],In 7 days"
  63. ) | sort -n | tr ',' ' '
  64. echo '.TE'
  65. }
  66. calendar() {
  67. verify_xxd calendar.csv
  68. # -t : preprocess with tbl(1)
  69. # grep -v '^$' : remove empty lines
  70. calendar_gen | groff -t -Dutf-8 -Tutf8 | grep -v '^$'
  71. }
  72. todo() {
  73. verify_xxd todo.csv
  74. todo_gen | groff -t -Dutf-8 -Tutf8 | grep -v '^$'
  75. }
  76. if [[ "$1" == "-h" ]]; then
  77. headers=false
  78. shift
  79. fi
  80. case "$1" in
  81. c*)
  82. calendar
  83. ;;
  84. t*)
  85. todo
  86. ;;
  87. h*)
  88. usage
  89. ;;
  90. *)
  91. todo
  92. echo
  93. calendar
  94. ;;
  95. esac