tpast
2.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#!/bin/sh
##
# various functions and aliases that make gcal more convinient
#
# Author: Georg Hopp <ghopp@bigpoint.net>
# Date: Tue Apr 17 17:19:56 CEST 2012
# Version: 1.0.0
#
alias gcal='LC_MESSAGES=de_DE.UTF-8 /usr/bin/gcal -K -s Monday'
alias hollidays='gcal -qde_hh -n'
alias dates='gcal -c'
alias mdates='gcal -cm'
alias tcomingf='tcoming | sed '\''1!d'\'
alias ttomorrowf='ttomorrow | sed '\''1!d'\'
function terms() {
_terms "all" 1 "$@"
}
function tcoming() {
_terms "coming" 1
}
function tpast() {
_terms "past" 1
}
function ttomorrow() {
_terms "all" 0 -ct
}
function _terms() {
local modifier=${1:-all}
local color=${2:-0}
local current_time=`date +%H:%M`
shift 2
#dates "$@" | sed '1,/^Fixed date/d; /^$/d; s/[^:]*: //'
dates "$@" | awk -v ctime="${current_time}" -v mod="${modifier}" \
-v col=${color} -v format=${DATES_FORMAT} '
BEGIN {
chour = ctime; gsub(/:.*/, "", chour);
cminute = ctime; gsub(/.*:/, "", cminute);
ctime = chour * 60 + cminute
}
NR == 1, /^Fixed date/ {next}
/^$/ {next}
{
gsub(/^[^:]*: /, "");
FS=" ";
hour=$1; gsub(/:.*/, "", hour);
minute=$1; gsub(/.*:/, "", minute);
time = hour * 60 + minute
color=""
if (format == "i3bar") {
if (col != 0 && time != 0 && time-ctime <= 15)
color="\"color\":\"#00FF00\",";
if (col != 0 && time != 0 && time-ctime <= 5)
color="\"color\":\"#FFFF00\",";
if (col != 0 && time != 0 && time-ctime <= 0)
color="\"color\":\"#FF0000\",";
}
else {
if (col != 0 && time != 0 && time-ctime <= 15)
color="\033[38;5;82m";
if (col != 0 && time != 0 && time-ctime <= 5)
color="\033[38;5;190m";
if (col != 0 && time != 0 && time-ctime <= 0)
color="\033[38;5;124m";
}
if ((mod == "all") ||
(mod == "coming" && (time+5 >= ctime || time == 0)) ||
(mod == "past" && (time < ctime || time == 0))) {
gsub(/\\/, "", $0);
if (format == "i3bar") {
gsub(/"/, "\\\"", $0);
out = color "\"full_text\":\"" $0 "\""
}
else {
out = color $0 "\033[00m"
}
print out
}
}
END {
if ("" == out) {
if (format == "i3bar") {
print "\"full_text\":\"none\""
}
else {
print "none"
}
}
}'
}
test "X$(basename -- "$0")" = "Xgcal" && gcal "$@"
test "X$(basename -- "$0")" = "Xhollidays" && hollidays "$@"
test "X$(basename -- "$0")" = "Xdates" && dates "$@"
test "X$(basename -- "$0")" = "Xmdates" && mdates "$@"
test "X$(basename -- "$0")" = "Xtcomingf" && tcomingf "$@"
test "X$(basename -- "$0")" = "Xttomorrowf" && ttomorrowf "$@"
test "X$(basename -- "$0")" = "Xtcoming" && tcoming "$@"
test "X$(basename -- "$0")" = "Xtpast" && tpast "$@"
test "X$(basename -- "$0")" = "Xttomorrow" && ttomorrow "$@"
test "X$(basename -- "$0")" = "Xterms" && terms "$@"
# vim: set ft=sh ts=4 sw=4: