#!/usr/bin/env bash
# 
# SCRIPT NAME:
# todo
#
# AUTHOR:
# Severin Kaderli <severin@kaderli.dev>
#
# DESCRIPTION:
# Lists the TODOs.
#
# USAGE:
# ./todo
clear

while read -r line
do
    task=$(echo "${line}" | cut -d "," -f 6)
    project=$(echo "${line}" | cut -d "," -f 4 | sed -e "s/^#//")
    datetime=$(echo "${line}" | cut -d "," -f 3)
    echo -e "[${datetime}][${project}]\n☐ ${task}\n"
done <<< "$(todoist s && todoist --csv list --filter "(overdue | today)")"


TODOS=$(rg -g "!todo" --hidden --no-heading -n "TODO:" "${HOME}/dotfiles" "${HOME}/Projects")
if [ -n "${TODOS}" ]; then
    while read -r line; do
        file=$(echo "${line}" | cut -d ":" -f 1 | sed -e "s/^[[:space:]]*//")
        lineNumber=$(echo "${line}" | cut -d ":" -f 2 | sed -e "s/^[[:space:]]*//")
        task=$(echo "${line}" | cut -d ":" -f 4 | sed -e "s/^[[:space:]]*//")
        echo -e "[Line ${lineNumber}][${file}]\n☐ ${task}\n"
    done <<< "${TODOS}"
fi
