tsk.sh

simple task list viewer
[raw]

01: #!/bin/bash
02: # @desc simple task list viewer
03: TASKFILE=~/tasks.txt
04: 
05: sedhl(){
06:         HL="$(tput setaf $1)$(tput bold)"
07:         RS="$(tput sgr0)"
08:         sed -u "s/$2/${HL}\0${RS}/"
09: }
10: 
11: taskfmt() {
12:         sedhl 1 "0d" | sedhl 3 "[1-3]d" | sedhl 2 "[4-7]d" 
13: }
14: 
15: show_tasks(){
16:         awk -F ' ' '{gsub("-"," ",$1);days=int((mktime($1" 00 00 00")-systime())/(24*60*60)+.5);gsub(" ","-",$1);$1=NR":"$1" "days"d";print $0}' "$TASKFILE" | taskfmt
17: }
18: show_tasks_day(){
19:         awk -F ' ' -v"period=$(date --date="$1" +%s)" '{gsub("-"," ",$1);t=mktime($1" 00 00 00");days=int((t-systime())/(24*60*60)+.5);gsub(" ","-",$1);$1=NR":"$1" "days"d";if(t<period) print $0}' "$TASKFILE" | taskfmt
20: }
21: 
22: touch $TASKFILE
23: case $1 in
24:         x)
25:                 sed -i "$2 d" "$TASKFILE"
26:                 show_tasks
27:                 exit    
28:         ;;
29: esac
30: if [[ $# -eq 1 && -n "$1" ]]
31: then
32:         show_tasks_day "$1"
33:         exit
34: fi
35: if [ $# -eq 0 ]
36: then
37:         show_tasks 
38:         exit
39: fi
40: echo $(date --date="$1" -I) ${@:2} | sort -o "$TASKFILE" -m - "$TASKFILE"
41: show_tasks 
42: