#!/bin/bash
if [ -f $HOME/.dmenurc ]
then
source $HOME/.dmenurc
else
DMENU='dmenu -i'
fi
TERMINAL=st
if [ -e ~/.when/preferences ]
then
calendar="$(head -n 1 ~/.when/preferences | awk '{print $3}' )"
else
$TERMINAL -e when
exit
fi
options="--noheader --wrap=0 --noampm" # the first two are important, please don't remove them
choice=$(echo -e "show\nadd\nspecial\nedit" | $DMENU -p 'choose an action:')
case $choice in
show)
wmy=$(echo -e "week\nmonth\nyear" | $DMENU -p 'show events of coming')
case $wmy in
week)
when $options w | $DMENU -p 'events of coming week:'
;;
month)
when $options m | $DMENU -p 'events of coming month:'
;;
year)
when $options y | $DMENU -p 'events of coming year'
;;
esac
;;
add)
year=$(date +%Y | $DMENU -p 'year:')
if [ ! "$year" ];then exit;fi
month=$(echo -e "Jan\nFeb\nMar\nApr\nMay\nJun\nJul\nAug\nSep\nOct\nNov\nDec" | $DMENU -p 'month:')
if [ ! "$month" ];then exit;fi
case $month in
Jan|Mar|May|Jul|Aug|Oct|Dec)
day=$(echo {01..31} | sed 's/\ /\n/g' | $DMENU -p 'month:')
;;
Feb)
if [ $[$year % 400] -eq "0" ]
then
day=$(echo {01..29} | sed 's/\ /\n/g' | $DMENU -p 'month:')
elif [ $[$year % 4] -eq 0 ]
then
if [ $[$year % 100] -ne 0 ]
then
day=$(echo {01..29} | sed 's/\ /\n/g' | $DMENU -p 'month:')
else
day=$(echo {01..28} | sed 's/\ /\n/g' | $DMENU -p 'month:')
fi
else day=$(echo {01..28} | sed 's/\ /\n/g' | $DMENU -p 'month:')
fi
;;
Apr|Jun|Sep|Nov)
day=$(echo {01..30} | sed 's/\ /\n/g' | $DMENU -p 'month:')
;;
esac
if [ ! "$day" ];then exit;fi
time=$(date +%H:%M | $DMENU -p 'time (can be left blank):')
event=$(xsel -o | $DMENU -p 'event:')
if [ ! "$event" ];then exit;fi
echo "$year $month $day , $time $event" >> $calendar
;;
special)
specialcase=$(echo -e "birthday\nyearly\nmonthly\nweekly\ncustom" | $DMENU -p 'choose a special case:')
case $specialcase in
birthday)
who="$(xsel -o | $DMENU -p 'who is the birthday kid?')"
if [ ! "$who" ];then exit;fi
year=$(xsel -o | $DMENU -p "what year was $who born?")
if [ ! "$year" ];then exit;fi
month=$(echo -e "Jan\nFeb\nMar\nApr\nMay\nJun\nJul\nAug\nSep\nOct\nNov\nDec" | $DMENU -p "what month was $who born?")
if [ ! "$month" ];then exit;fi
case $month in
Jan|Mar|May|Jul|Aug|Oct|Dec)
day=$(echo {01..31} | sed 's/\ /\n/g' | $DMENU -p 'month:')
;;
Feb)
if [ $[$year % 400] -eq "0" ]
then
day=$(echo {01..29} | sed 's/\ /\n/g' | $DMENU -p 'month:')
elif [ $[$year % 4] -eq 0 ]
then
if [ $[$year % 100] -ne 0 ]
then
day=$(echo {01..29} | sed 's/\ /\n/g' | $DMENU -p 'month:')
else
day=$(echo {01..28} | sed 's/\ /\n/g' | $DMENU -p 'month:')
fi
else day=$(echo {01..28} | sed 's/\ /\n/g' | $DMENU -p 'month:')
fi
;;
Apr|Jun|Sep|Nov)
day=$(echo {01..30} | sed 's/\ /\n/g' | $DMENU -p 'month:')
;;
esac
echo "${year}* $month $day , BIRTHDAY: ${who}s \a. birthday (\y)" >> $calendar
;;
yearly)
month=$(echo -e "Jan\nFeb\nMar\nApr\nMay\nJun\nJul\nAug\nSep\nOct\nNov\nDec" | $DMENU -p 'month:')
if [ ! "$month" ];then exit;fi
case $month in
Jan|Mar|May|Jul|Aug|Oct|Dec)
day=$(echo {01..31} | sed 's/\ /\n/g' | $DMENU -p 'month:')
;;
Feb)
if [ $[$year % 400] -eq "0" ]
then
day=$(echo {01..29} | sed 's/\ /\n/g' | $DMENU -p 'month:')
elif [ $[$year % 4] -eq 0 ]
then
if [ $[$year % 100] -ne 0 ]
then
day=$(echo {01..29} | sed 's/\ /\n/g' | $DMENU -p 'month:')
else
day=$(echo {01..28} | sed 's/\ /\n/g' | $DMENU -p 'month:')
fi
else day=$(echo {01..28} | sed 's/\ /\n/g' | $DMENU -p 'month:')
fi
;;
Apr|Jun|Sep|Nov)
day=$(echo {01..30} | sed 's/\ /\n/g' | $DMENU -p 'month:')
;;
esac
if [ ! "$day" ];then exit;fi
time=$(date +%H:%M | $DMENU -p 'time (can be left blank):')
event=$(xsel -o | $DMENU -p 'event:')
if [ ! "$event" ];then exit;fi
echo "m=$month & d=$day , $time $event" >> $calendar
;;
monthly)
day=$(echo {01..31} | sed 's/\ /\n/g' | $DMENU -p 'day of the month:')
if [ ! "$day" ];then exit;fi
time=$(date +%H:%M | $DMENU -p 'time (can be left blank):')
event=$(xsel -o | $DMENU -p 'event:')
if [ ! "$event" ];then exit;fi
echo "d=$day , $time $event" >> $calendar
;;
weekly)
day=$(echo -e "Mon\nTue\nWed\nThu\nFri\nSat\nSun" | $DMENU -p 'weekday:')
if [ ! "$day" ];then exit;fi
time=$(date +%H:%M | $DMENU -p 'time (can be left blank):')
event=$(xsel -o | $DMENU -p 'event:')
if [ ! "$event" ];then exit;fi
echo "w=$day , $time $event" >> $calendar
;;
custom)
fancycustominput="$(xsel -o | $DMENU -p 'fancy custom input:')"
if [ ! "$fancycustominput" ];then exit;fi
echo "$fancycustominput" >> $calendar
esac
;;
edit)
$TERMINAL -e when e
esac