-
-
Save lamberta/1256263 to your computer and use it in GitHub Desktop.
Display calendar agenda using the Google command line tool.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
function print_help { | |
echo "Display the week's agenda from Google Calendar." | |
echo "Usage: $(basename $0) [options]" | |
echo " -h Show this usage guide." | |
echo " -t Today's agenda." | |
echo " -m Month agenda." | |
echo " -E Only display Event calendar." | |
echo "[Add event]" | |
echo " -a=event Add calendar event." | |
echo " -d=date Date to add event." | |
} | |
GOOGLECL=$(which google) | |
if [ ! -x "$GOOGLECL" ]; then | |
echo "Error: Requires the Google command line tool." | |
exit 1 | |
fi | |
function display_calendar { | |
if [ -n "$MONTH_VIEW" ]; then | |
cal -3 | |
else | |
cal | |
fi | |
if [ -n "$TODAY_VIEW" ]; then | |
echo -e "\nAgenda for $DATE_FROM:" | |
else | |
echo -e "\nAgenda for $DATE_FROM to $DATE_TO:" | |
fi | |
if [ -z "$CALS" ]; then | |
CALS=".*" #if no calendar specified, show all | |
fi | |
$GOOGLECL calendar list --cal "$CALS" --date "$DATE_FROM,$DATE_TO" --delimiter ": " | |
} | |
function add_event { | |
$GOOGLECL calendar add "$EVENT_MSG$EVENT_DATE" | |
} | |
#parse args | |
while getopts "mtEa:d:h" option; do | |
case $option in | |
m) DATE_TO=$(date --date="1 month" +"%F"); MONTH_VIEW=1;; | |
t) DATE_TO=$(date +"%F"); TODAY_VIEW=1;; | |
E) CALS="Events";; | |
a) EVENT_MSG="$OPTARG";; | |
d) EVENT_DATE=", $OPTARG";; | |
h) print_help; exit 0;; | |
\?) print_help; exit 0;; | |
esac | |
done | |
if [ -n "$EVENT_MSG" ]; then | |
add_event | |
exit 0 | |
fi | |
DATE_FROM=$(date +"%F") #today | |
if [ -z "$DATE_TO" ]; then | |
DATE_TO=$(date --date="1 week" +"%F") | |
fi | |
display_calendar |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment