agenda.tcl (1362B)
1 #!/usr/bin/env tclsh8.6 2 3 array set colors { 4 black "\033\[1;30m" 5 red "\033\[1;31m" 6 green "\033\[1;32m" 7 yellow "\033\[1;33m" 8 blue "\033\[1;34m" 9 magenta "\033\[1;35m" 10 cyan "\033\[1;36m" 11 white "\033\[1;37m" 12 end "\033\[0m" 13 } 14 15 proc print {text in color} { 16 global colors 17 puts -nonewline $colors($color) 18 puts -nonewline $text 19 puts $colors(end) 20 } 21 22 if {[llength $argv] > 0 & [lindex $argv 0] eq {next}} { 23 set next next 24 set time [clock scan "next week"] 25 } else { 26 set next {} 27 set time [clock seconds] 28 } 29 30 lassign [clock format $time -format "%W %d %m %Y"] \ 31 week day month year 32 33 if {$next ne {}} { 34 set day -1 35 } 36 37 set calendar [open "/home/anton/data/planing/calendar.txt"] 38 set lines [split [read $calendar] "\n"] 39 close $calendar 40 41 foreach line $lines { 42 # year 43 if {[string first "$year " $line] == 0} { 44 print $line in red 45 continue 46 } 47 # month 48 if {[string first "$year-$month " $line] == 0} { 49 print $line in yellow 50 continue 51 } 52 # today, print green 53 if {[string first "$year-$month-$day " $line] == 0} { 54 print $line in green 55 continue 56 } 57 # another days of week 58 if {[string first "w$week" $line] > -1 & \ 59 [string first "$year-" $line] == 0} { 60 puts $line 61 continue 62 } 63 }