#!/bin/sh ## Mail2Khal # # Converts an email passed as stdin into a khal calendar event. # To use in conjunction with neomutt add this to the config: # # macro attach c 'mail2khal' # which khal >/dev/null 2>&1 || \ ( echo "Install 'khal' to use this script." && exit 1 ) TMP="$(mktemp --tmpdir=$TMPDIR mail2khal.XXXXXXXX.md)" echo " > Fill all sections of this markdown file (time and title are > mandatory). Quote blocks (like this one) are ignored. Empty > lines are ignored unless in the description section. # Calendar university # Title # Time > Valid examples are: > [dd/mm[/yyyy]] [hh:mm] [[dd/mm[/yyyy]] [hh:mm]] > {today,tomorrow,monday,...,sunday} can be used as date # Location # Tags # Description # Ignored > Anything after this point is ignored. " > "$TMP" cat - >> "$TMP" # Make the necessary changes in Nvim nvim "$TMP" awk ' /^>/ { next } /^# Calendar$/ { state = 1 cal = "" next } /^# Title$/ { state = state + 1 title = "" next } /^# Time$/ { state = state + 1 time = "" next } /^# Location$/ { state = state + 1 loc = "" next } /^# Tags$/ { state = state + 1 tags = "" next } /^# Description$/ { state = state + 1 desc = "" next } /^# Ignored$/ { cmd = "khal new" if (length(cal) > 0) { cmd = cmd " -a " cal } if (length(loc) > 0) { cmd = cmd " -l \"" loc "\"" } if (length(tags) > 0) { cmd = cmd " -g \"" tags "\"" } cmd = cmd " \"" time "\"" cmd = cmd " \"" title if (length(desc) > 0) { cmd = cmd " :: " desc } cmd = cmd "\"" system(cmd) exit } state == 1 && NF { cal = cal $0 } state == 2 && NF { title = title $0 } state == 3 && NF { time = time $0 } state == 4 && NF { loc = loc $0 } state == 5 && NF { tags = tags $0 } state == 6 { desc = desc "\n" $0 } ' "$TMP"