75 lines
1.6 KiB
Bash
Executable File
75 lines
1.6 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
me="$(basename $0)"
|
|
|
|
textToDate ()
|
|
{
|
|
if [ ! "$(grep -P "(\d\d\.?){3}" <<< "$1")" ]
|
|
then
|
|
d=$(sed 's/^\(next\|n\)$/tomorrow/' <<< "$1")
|
|
date --date="$d" +"%Y-%m-%d" || exit 1
|
|
else
|
|
echo "$1";
|
|
fi
|
|
}
|
|
|
|
if [ "$1" = "usage" ]
|
|
then
|
|
echo " hw"
|
|
echo " list homework"
|
|
echo " hw add"
|
|
echo " prompt for adding an assignment"
|
|
echo " hw [due date] [class] [description]"
|
|
echo " add an assignment without a prompt"
|
|
echo " hw [date]"
|
|
echo " list assignments due on [date]"
|
|
echo " hw rel"
|
|
echo " list assignments with the dates in days relative to today"
|
|
exit 0
|
|
fi
|
|
shift
|
|
|
|
if [ "$1" = "add" ]
|
|
then
|
|
read -p "Due: " due
|
|
due="$(textToDate "$date")"
|
|
read -p "Class: " class
|
|
read -p "Description: " desc
|
|
"$TODO_FULL_SH" add "(B) +hw" "class:$class $due $desc"
|
|
elif [ "$1" = "rel" ]
|
|
then
|
|
"$TODO_FULL_SH" "$me" | sed -e "s/.*/echo \'&\'/g;s/due:\([0-9-]*\)/due:\'"'$(( ($(date --date="\1" +%s) - $(date --date="00:00" +%s)) \/ 86400 ))'"\'d/ge"
|
|
elif [ -n "$1" -a -n "$2" -a -n "$3" ]
|
|
then
|
|
due="due:$(textToDate "$1")" || { echo "invalid date" ; exit 1; }
|
|
shift
|
|
class="class:$1"
|
|
shift
|
|
"$TODO_FULL_SH" add "(B) +hw $due $class $@"
|
|
else
|
|
IFS=$'\n'
|
|
today=$(textToDate "today" | tr -d '-')
|
|
if [ -n "$1" ]
|
|
then
|
|
inDate="$(textToDate "$1" | tr -d '-' | cut -f1)"
|
|
fi
|
|
x=0
|
|
for i in $("$TODO_FULL_SH" list | grep "+hw")
|
|
do
|
|
x=$(($x+1))
|
|
date=$(grep -oP "due:\K[0-9-]*" <<< "$i"| tr -d '-' | cut -f1)
|
|
if [ "$date" -le "$today" ]
|
|
then
|
|
echo "$i" | sed "s/\(due:[0-9-]*\)/$(tput bold)\1$(tput sgr0)/g"
|
|
elif [ -n "$inDate" ]
|
|
then
|
|
if [ "$date" -eq "$inDate" ]
|
|
then
|
|
echo "$i"
|
|
fi
|
|
else
|
|
echo "$i"
|
|
fi
|
|
done
|
|
fi
|