Update 'clean-tw.sh'

The script is now safer and works for task ids bigger than 99!
This commit is contained in:
Daniel Mowitz 2023-05-25 16:36:03 +02:00
parent 90d18d7392
commit c56f8995e1

View file

@ -1,20 +1,22 @@
#!/bin/sh
function get_task_value {
echo "$task_data" | grep "^$1" | sed -E "s/^$1 +//"
echo "$task_data" | grep "^$1" | sed -E "s/^$1 +//"
}
ids=$(task limit:none recur | grep -E '^ +[[:digit:]].*[[:alpha:]].*[[:digit:]]$' | sed -E 's/^ +([[:digit:]]+) .*/\1/')
ids=$(task limit:none recur | grep -E '^ ?[[:digit:]].*[[:alpha:]].*[[:digit:]]$' | sed -E 's/^ ?([[:digit:]]+) .*/\1/')
excluded_ids=$(for id in $ids
do
task_data="$(task $id)"
echo "$(get_task_value 'Parent task') $(get_task_value 'Description' | sed 's/ /_/g') $(get_task_value 'Due') $id"
done | sort | rev | uniq -f3 | rev | sed -E 's/.* ([[:digit:]]+)$/\1/')
do
task_data="$(task $id)"
echo "$(get_task_value 'Parent task') $(get_task_value 'Description' | sed 's/ /_/g') $(get_task_value 'Due') $id"
done | sort | rev | uniq -f3 | rev | sed -E 's/.* ([[:digit:]]+)$/\1/')
del_ids=$(for id in $excluded_ids $ids
do
echo $id
done | sort | uniq -u)
do
echo $id
done | sort | uniq -u)
task $del_ids del
if [ ! -z "$del_ids" -a "$del_ids" != " " ]
then
task $del_ids del
fi