You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
67 lines
1.5 KiB
67 lines
1.5 KiB
#!/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:
|