timey-whyme.sh (1765B)
- #!/bin/sh
- # SPDX-FileCopyrightText: 2017-2022 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me>
- # SPDX-License-Identifier: MPL-2.0
- xdd="${XDG_DATA_DIR:-$HOME/.local/share}/timey-whyme"
- today="$(date --date=now +%Y-%m-%d)"
- later="$(date --date=+7days +%Y-%m-%d)"
- headers=true
- usage() {
- echo "$0"' [t…|c…|h…]
- c…: show calendar
- t…: show todo
- h…: this help'
- echo '
- Files used:
- • '"$xdd"'/calendar.csv
- • '"$xdd"'/todo.csv'
- echo '
- Environment used:
- XDG_DATA_DIR (defaults to “~/.local/share”)'
- }
- die() {
- echo "$1"
- exit
- }
- verify_xxd() {
- [ -e "${xdd}/${1}" ] || die "Please create the following file, see examples for help: ${xdd}/${1}"
- }
- todo_gen() {
- # (GNU-ism) nowarn: turn off warning: table wider than line width
- echo \
- '.color 1
- .TS
- nowarn;
- llll.'
- $headers && echo \
- '.TH
- Deadline Nice Description Location
- .TB
- _'
- (
- cut -d '#' -f -1 "$xdd/todo.csv" | grep -v '^$'
- echo "${today},\m[blue],Now"
- echo "${later},\m[],In 7 days"
- ) | sort -n | tr ',' ' '
- echo '.TE'
- }
- calendar_gen() {
- # (GNU-ism) nowarn: turn off warning: table wider than line width
- echo \
- '.color 1
- .TS
- nowarn;
- llll.'
- $headers && echo \
- '.TH
- Start End Description Location
- .TB
- _'
- (
- cut -d '#' -f -1 "$xdd/calendar.csv" | grep -v '^$'
- echo "${today},\m[blue],Now"
- echo "${later},\m[],In 7 days"
- ) | sort -n | tr ',' ' '
- echo '.TE'
- }
- calendar() {
- verify_xxd calendar.csv
- # -t : preprocess with tbl(1)
- # grep -v '^$' : remove empty lines
- calendar_gen | groff -t -Dutf-8 -Tutf8 | grep -v '^$'
- }
- todo() {
- verify_xxd todo.csv
- todo_gen | groff -t -Dutf-8 -Tutf8 | grep -v '^$'
- }
- if [ "$1" = "-h" ]; then
- headers=false
- shift
- fi
- case "$1" in
- c*)
- calendar
- ;;
- t*)
- todo
- ;;
- h*)
- usage
- ;;
- *)
- todo
- echo
- calendar
- ;;
- esac