registrar

Files related to my duties as Registrar of Agora Nomic
git clone git://juanmeleiro.mat.br/registrar
Log | Files | Refs | README

birthday.fish (1223B)


      1 #!/usr/bin/fish
      2 
      3 set WIDTH 80
      4 
      5 function ord -a num
      6 	switch "$num"
      7 	case 1 01
      8 		echo st
      9 	case 2 02
     10 		echo nd
     11 	case 3 03
     12 		echo rd
     13 	case '*'
     14 		echo th
     15 	end
     16 end
     17 
     18 fzf < birthdays/list |
     19 read date name
     20 
     21 echo $date | read -d '-' birthyear month day
     22 
     23 set currentyear (date +%Y)
     24 set currentstamp (date +%S)
     25 set birthstamp (date +%S -d $date)
     26 
     27 if test (date +%S -d "$currentyear-$month-$day") -gt $currentstamp
     28 	# Most recent birthday was last year
     29 	set year (math $currentyear - 1)
     30 else
     31 	# Most recent birthday was this year
     32 	set year $currentyear
     33 end
     34 
     35 set MONTH (env LANG=en date +"%B" -d "$year-$month-$day")
     36 set DATEORD (ord $day)
     37 set COUNT (math "$year - $birthyear")
     38 set COUNTORD (ord "$COUNT")
     39 set DAY (string trim -l -c '0' $day)
     40 
     41 set DATE "The $DAY$DATEORD of $MONTH of $year"
     42 set DATELEN (string length "$DATE")
     43 set DATEPAD (repeat (math "floor(($WIDTH - $DATELEN)/2)") " ")
     44 
     45 set tmp (mktemp)
     46 begin
     47 echo 'Date: '(date -R)
     48 echo 'From: juan <juan@juanmeleiro.mat.br>'
     49 echo 'To: <agora-official@agoranomic.org>'
     50 echo 'Subject: [Registrar] Birthday Announcement'
     51 m4 --define=DATE="$DATEPAD$DATE" \
     52    --define=PLAYER="$name" \
     53    --define=COUNT="$COUNT$COUNTORD" \
     54    birthdays/template
     55 end > $tmp
     56 neomutt -E -H $tmp
     57 rm $tmp
     58