#!/bin/zsh usage() { echo "Usage: tanext [TASK_ID]" } verify_args() { if [[ $# -eq 0 ]]; then CURRENT_TASKS_JSON=$(task +ACTIVE export) MOTHER_UUID=$(echo "$CURRENT_TASKS_JSON" | jq -r '.[0].MOTHER') if [[ $(echo "$CURRENT_TASKS_JSON" | jq -r 'length') -ne 1 ]]; then echo "Something went wrong! The number of active tasks is not equal to 1." return 1 fi if [[ $(echo "$CURRENT_TASKS_JSON" | jq -r '.[0].SEQ_NEXT') == "null" ]]; then MOTHER_NEXT=$(task "$MOTHER_UUID" export | jq -r '.[0].SEQ_NEXT') if [[ "$MOTHER_NEXT" == "null" ]]; then echo "There is no next task." return 1 fi NEXT=$(task "$MOTHER_NEXT" export | jq -r '.[0].SEQ_CURRENT') else NEXT=$(echo "$CURRENT_TASKS_JSON" | jq -r '.[0].SEQ_NEXT') fi else usage return 1 fi } main() { fypm ta-done -s "$NEXT" task "$MOTHER_UUID" modify SEQ_CURRENT:"$NEXT" } verify_args $@ || exit 1 main