Skip to content

Instantly share code, notes, and snippets.

@kaz-utashiro
Last active December 30, 2015 02:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kaz-utashiro/7762629 to your computer and use it in GitHub Desktop.
Save kaz-utashiro/7762629 to your computer and use it in GitHub Desktop.
.greplrc definition to search iCal data and display in single line
######################################################################
# iCal
######################################################################
option --ical_data \
--chdir ~/Library/Calendars/*.caldav/*.calendar/Events \
--glob *.ics
help --ical Search iCal data
option --ical \
--all \
--ical_data \
--print print_ical_line
__CODE__
sub print_ical_line {
s/\r//g;
my $s = '';
my(@s, @e);
if (@s = /^DTSTART.*(\d{4})(\d\d)(\d\d)(?:T(\d\d)(\d\d))?/m) {
$s .= "$1/$2/$3";
$s .= " $4:$5" if defined $4;
}
if (@e = /^DTEND.*(\d{4})(\d\d)(\d\d)(?:T(\d\d)(\d\d))?/m) {
if ($s[0] eq $e[0] and $s[1] eq $e[1] and $s[2]+1 >= $e[2]) {
$s .= "-$4:$5" if defined $4;
} else {
$s .= "-";
$s .= "$1/" if $s[0] ne $e[0];
$s .= "$2/$3";
}
}
$s .= " ";
/^SUMMARY:(.*)/m and $s .= $1;
/^LOCATION:(.*)/m and $s .= " \@[$1]";
$s .= "\n";
$s;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment