diff options
author | Alexis Hovorka <[email protected]> | 2021-01-02 19:08:15 -0700 |
---|---|---|
committer | Alexis Hovorka <[email protected]> | 2021-01-02 19:08:15 -0700 |
commit | 0cb6fa7ea6dd6c6d17eb960e1a4a0cc9485ff29c (patch) | |
tree | 15aef185afecda8320aaced56198c425c705a43e /base/taskw | |
parent | bd3d114f9513ddda9a2947ca1f6c995638c2006c (diff) |
[feat] Add Taskwarrior aliases and custom reviewer
Diffstat (limited to 'base/taskw')
-rwxr-xr-x | base/taskw | 227 |
1 files changed, 227 insertions, 0 deletions
diff --git a/base/taskw b/base/taskw new file mode 100755 index 0000000..66230cc --- /dev/null +++ b/base/taskw @@ -0,0 +1,227 @@ +#!/bin/bash +# Taskwarrior Wrapper + +if [[ ! "$TASKBIN" ]]; then + TASKBIN="task" +fi + +DATEFMT="+%a %Y-%m-%d %H:%M" +prettyage() { + AGE=$(date -d "$1" +%s) + NOW=$(date +%s) + DIF=$((NOW - AGE)) + if ((DIF < 60)); then echo -n "${DIF}s" + elif ((DIF < 3600)); then echo -n "$((DIF / 60))m" + elif ((DIF < 86400)); then echo -n "$((DIF / 3600))h" + elif ((DIF < 1209600)); then echo -n "$((DIF / 86400))d" + elif ((DIF < 7776000)); then echo -n "$((DIF / 604800))w" + elif ((DIF < 31536000)); then echo -n "$((DIF / 2592000))m" + else echo -n "$((DIF / 31536000))y"; fi +} + +function exitaltscreen { + clear + tput rmcup + exit 0 +} + +CMD="$1" +shift + +case $CMD in + "") + TASKS="$($TASKBIN rc._forcecolor=yes rc.defaultwidth=$(tput cols) 2>&1 | + grep -v "mConfiguration override rc\.")" + if (( `tput lines` > `echo "$TASKS" | wc -l` )); then + echo "$TASKS" + else + echo "$TASKS" | less -R + fi + ;; + + projects) + $TASKBIN rc.context= rc.list.all.projects=1 rc.verbose=blank,label projects $@ + ;; + + review) # <filter> + TASKS="$($TASKBIN rc.context= $@ _review | shuf)" + TASKCOUNT="$(echo "$TASKS" | wc -l)" + TASKNUMBER=1 + LASTCMD="" + LASTRES="" + + if [[ "$TASKCOUNT" = "1" ]]; then + echo "Nothing to review" + exit + fi + + trap exitaltscreen SIGINT SIGTERM SIGQUIT + tput smcup + + #for ID in $TASKS; do + while ((TASKNUMBER <= TASKCOUNT)); do + ID="$(echo "$TASKS" | head -n$TASKNUMBER | tail -n1)" + + clear + for i in `seq $(( "$(tput lines)" / 2 - 8 ))`; do echo; done + echo -e "\e[38;5;19m$LASTRES" + echo -ne "\n\e[1;36;48;5;19m " + echo -ne "$TASKNUMBER/$TASKCOUNT " + TASKNUMBER=$((TASKNUMBER + 1)) + + PRIORITY="$($TASKBIN _get $ID.priority)" + if [[ "$PRIORITY" ]]; then + COLOR="0" + case $PRIORITY in + H) COLOR="1" ;; + M) COLOR="3" ;; + L) COLOR="8" ;; + esac + echo -ne "\e[0;38;5;19;48;5;${COLOR}m" + echo -ne "\e[0;38;5;${COLOR};48;5;18m" + echo -ne "\e[1;38;5;${COLOR}m $PRIORITY" + echo -ne "\e[0;48;5;18m " + else + echo -ne "\e[0;38;5;19;48;5;18m " + fi + + AGE="$(prettyage "$($TASKBIN _get $ID.entry)")" + echo -ne "\e[37m$AGE " + + #STATUS="$($TASKBIN _get $ID.status | tr -d "\n")" + #if [[ "$STATUS" != "pending" ]]; then echo -n "$STATUS "; fi + + if [[ "$($TASKBIN _get $ID.start)" ]]; then + echo -ne "\e[0;38;5;18;48;5;16m\e[0;38;5;16m\e[0m "; else + echo -ne "\e[0;38;5;18m\e[0m "; fi + #$TASKBIN _get $ID.id | tr -d "\n"; echo -n ". " + $TASKBIN _get $ID.description | tr "\n" " " + + echo -ne "\e[38;5;18m\e[0;48;5;18m " + TAGS="$($TASKBIN _get $ID.tags)" + PROJECT="$($TASKBIN _get $ID.project)" + if [[ "$TAGS" ]]; then + echo "$TAGS" | tr "," " " | while read TAG; do + if [[ "$TAG" = "next" ]]; then + echo -ne "\e[38;5;16m"; else + echo -ne "\e[38;5;17m"; fi + echo -ne "+$TAG " + done + fi + if [[ "$TAGS" && "$PROJECT" ]]; then + echo -ne "\e[30m " + fi + if [[ "$PROJECT" ]]; then + echo -ne "\e[38;5;20m$PROJECT" + fi + + echo -e "\e[K\e[0m" + DUE="$($TASKBIN _get $ID.due)" + #RECUR="$($TASKBIN _get $ID.recur)" # TODO + SCHED="$($TASKBIN _get $ID.scheduled)" + UNTIL="$($TASKBIN _get $ID.until)" + WAIT="$($TASKBIN _get $ID.wait)" + if [[ "$DUE$SCHED$UNTIL$WAIT" ]]; then echo + if [[ "$DUE" ]]; then echo -e "\e[31m Due: $(date -d "$DUE" "$DATEFMT")\e[0m"; fi + #if [[ "$RECUR" ]]; then echo -e "\e[36mRecurring: $RECUR\e[0m"; fi + if [[ "$SCHED" ]]; then echo " Scheduled for: $(date -d "$SCHED" "$DATEFMT")"; fi + if [[ "$UNTIL" ]]; then echo " Valid until: $(date -d "$UNTIL" "$DATEFMT")"; fi + if [[ "$WAIT" ]]; then echo " Hidden until: $(date -d "$WAIT" "$DATEFMT")"; fi + fi + + ANNOT=1 + if [[ "$($TASKBIN _get $ID.annotations.$ANNOT.entry)" ]]; then + echo -e "\n \e[1;4;34mAnnotations\e[0m"; fi + while [[ "$($TASKBIN _get $ID.annotations.$ANNOT.entry)" ]]; do + echo -ne "\e[33m " + date -d "$($TASKBIN _get $ID.annotations.$ANNOT.entry)" "+%Y-%m-%d" | tr "\n" " " + echo -ne "\e[0m- " + $TASKBIN _get $ID.annotations.$ANNOT.description + ANNOT=$((ANNOT + 1)) + done + + DEPENDS="$($TASKBIN _get $ID.depends | tr "," "\n" | while read DID; do + if [[ "$DID" && "$($TASKBIN _get $DID.id)" != 0 ]]; then echo "$DID"; fi + done)" + if [[ "$DEPENDS" ]]; then + echo -e "\n \e[1;4;38;5;17mThis Depends On\e[0m" + echo "$DEPENDS" | while read DID; do + echo -n " - " + $TASKBIN _get $DID.description + done + fi + + DEPENDENTS="$($TASKBIN depends:$ID _uuids)" + if [[ "$DEPENDENTS" ]]; then + echo -e "\n \e[1;4;32mTasks Depending On This\e[0m" + echo "$DEPENDENTS" | while read DID; do + echo -n " - " + $TASKBIN _get $DID.description + done + fi + + NAGS="$( + if [[ ! "$PROJECT" ]]; then echo "Doesn't have a project!"; fi + )" + if [[ "$NAGS" ]]; then + echo -e "\e[0;1;31m" + echo "$NAGS" | sed "s/^/ /" + fi + + echo -e "\n\e[0;90m (enter) next, (s)kip, (c)omplete, <modify...>" + echo " (d)elete, (e)dit, (n)ew task, (u)ndo, (q)uit" + echo -ne "\e[0;38;5;16m\e[0m " + read IN + + case $IN in + "") $TASKBIN $ID modify reviewed:now &>/dev/null + LASTRES="Marked as reviewed." ;; + c) $TASKBIN $ID done &>/dev/null + LASTRES="Marked complete." ;; + d) $TASKBIN $ID delete &>/dev/null + LASTRES="Deleted." ;; + s) LASTRES="Skipped." ;; + e) $TASKBIN $ID edit + $TASKBIN $ID modify reviewed:now &>/dev/null + LASTRES="Edited." ;; + + n) echo -ne "\n New Task:\n\e[0;38;5;16m\e[0m " + read NEWTASK + if [[ "$NEWTASK" ]]; then + $TASKBIN add $NEWTASK &>/dev/null + fi + TASKNUMBER=$((TASKNUMBER - 1)) + LASTRES="Created: $NEWTASK" ;; + + u) if [[ "$TASKNUMBER" = "2" ]]; then # Command running on #1 + TASKNUMBER=$((TASKNUMBER - 1)) # Because it was already incremented + if echo "$LASTCMD" | grep -qi '^n$'; then + yes yes | task undo &>/dev/null + LASTRES="Reverted." + fi + else + if echo "$LASTCMD" | grep -qvi '^n$'; then + TASKNUMBER=$((TASKNUMBER - 2)); else + TASKNUMBER=$((TASKNUMBER - 1)); fi + if echo "$LASTCMD" | grep -qvi '^s$'; then + yes yes | task undo &>/dev/null + fi + LASTRES="Reverted." + fi ;; + + q) exitaltscreen ;; + *) $TASKBIN $ID modify $IN reviewed:now &>/dev/null + LASTRES="Modified: $IN" ;; + esac + + LASTCMD="$IN" + done + + # TODO triggers for new tasks + exitaltscreen + ;; + + *) + task $CMD $@ + ;; +esac |