i3overdue
1.53 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
#!/bin/sh
alias i3active='task i3active 2>/dev/null | sed '\''4!d'\'''
alias i3next='task i3next 2>/dev/null | sed '\''4!d'\'''
alias i3overdue='task i3overdue 2>/dev/null | sed '\''4!d'\'''
alias odcnt='task overdue 2>/dev/null | sed '\''$!d;s/task.*/overdue/'\'''
function i3odcnt() {
echo "\"color\":\"#FF0000\",\"full_text\":\"$(odcnt)\""
}
function i3tasko() {
_i3print "$(i3overdue)"
}
function i3task() {
local TASK="$(i3active)"
test -z "${TASK}" && TASK="$(i3next)"
_i3print "${TASK}"
}
function _taskdate() {
local TDATE
TDATE="$(echo "${1}" | sed 's/^\([0-9]*\)\.\([0-9]*\)\.\([0-9]*\).*/\3-\2-\1/')"
test "${TDATE}" == "${1}" && TDATE="3000-12-12"
echo "${TDATE}"
}
function _taskmsg() {
echo "${1}" | sed 's/^[0-9.]* *//'
}
function _taskcol() {
local ACTIVE_COL="#4040FF"
local ONEDAY_COL="#FFFF00"
local OVERDUE_COL="#FF0000"
local COLOR="#00FF00"
test "$(i3active)" == "${1}" && {
echo "${ACTIVE_COL}"
return
}
# add one day to due date as the due date has also 24 hours
local DUE=$(($(date -d "$(_taskdate "${1}")" +%s)+(24*60*60)))
local NOW=$(date +%s)
test ${DUE} -le $((${NOW}+(24*60*60))) && COLOR="${ONEDAY_COL}"
test ${DUE} -le ${NOW} && COLOR="${OVERDUE_COL}"
echo "${COLOR}"
}
function _i3print() {
printf "\"color\":\"%s\",\"full_text\":\"%s\"" \
"$(_taskcol "${1}")" \
"$(_taskmsg "${1}")"
}
test "X$(basename -- "$0")" = "Xi3task" && i3task "$@"
test "X$(basename -- "$0")" = "Xi3overdue" && i3tasko "$@"
test "X$(basename -- "$0")" = "Xi3odcnt" && i3odcnt "$@"
# vim: set ft=sh ts=4 sw=4: