Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Add next agenda to terminal
Add this line to the crontab to cache the agenda every 10 minutes
*/10 * * * * OUT=$(/usr/bin/gcalcli --tsv --nostarted agenda "`date`") && echo "$OUT" > $HOME/.gcalcli-agenda-cache
This is part of my tmux config to include it:
tmux_conf_theme_status_left='  #($HOME/bin/next_agenda.sh) | #{prefix}#{pairing}#{synchronized}'
tmux_conf_theme_status_right='#{?battery_status, #{battery_status},}#{?battery_bar, #{battery_bar},}#{?battery_percentage, #{battery_percentage},} | #{username}#{root} | #{hostname} |'
set -g status-interval 10
#!/bin/bash
function rel_fmt_low_precision() {
local SEC_PER_MINUTE=$((60))
local SEC_PER_HOUR=$((60*60))
local SEC_PER_DAY=$((60*60*24))
local SEC_PER_MONTH=$((60*60*24*30))
local SEC_PER_YEAR=$((60*60*24*365))
local last_unix="$(date --date="$*" +%s)" # convert date to unix timestamp
local now_unix="$(date +'%s')"
local delta_s=$(( now_unix - last_unix ))
if(( delta_s > 0))
then
if (( delta_s < SEC_PER_MINUTE * 2))
then
echo ""$((delta_s))" seconds ago"
return
elif (( delta_s < SEC_PER_HOUR * 2))
then
echo ""$((delta_s / SEC_PER_MINUTE))" minutes ago"
return
elif (( delta_s < SEC_PER_DAY * 2))
then
echo ""$((delta_s / SEC_PER_HOUR))" hours ago"
return
elif (( delta_s < SEC_PER_MONTH * 2))
then
echo ""$((delta_s / SEC_PER_DAY))" days ago"
return
elif (( delta_s < SEC_PER_YEAR * 2))
then
echo ""$((delta_s / SEC_PER_MONTH))" months ago"
return
else
echo ""$((delta_s / SEC_PER_YEAR))" years ago"
return
fi
else
if (( delta_s > SEC_PER_MINUTE * -2))
then
echo "in "$((-1 * delta_s))" seconds"
return
elif (( delta_s > SEC_PER_HOUR * -2))
then
echo "in "$((-1 * delta_s / SEC_PER_MINUTE))" minutes"
return
elif (( delta_s > SEC_PER_DAY * -2))
then
echo "in "$((-1 * delta_s / SEC_PER_HOUR))" hours"
return
elif (( delta_s > SEC_PER_MONTH * -2))
then
echo "in "$((-1 * delta_s / SEC_PER_DAY))" days"
return
elif (( delta_s > SEC_PER_YEAR * -2))
then
echo "in "$((-1 * delta_s / SEC_PER_MONTH))" months"
return
else
echo "in "$((-1 * delta_s / SEC_PER_YEAR))" years"
return
fi
fi
}
NOW=$(date +%s)
next_agenda() {
while read -r line; do
read -d "\t" T1 T2 EVENT <<< $line
DATE=$(date -d "$T1 $T2" +%s)
if [ $DATE -ge $NOW ];
then
echo $(rel_fmt_low_precision "$T1 $T2") $EVENT
break
fi
done <<< "$((cat ~/.gcalcli-agenda-cache || gcalcli --cache --tsv --nostarted agenda '`date`' '11:59pm') | cut -d$'\t' -f1,2,5-)"
}
next_agenda
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.