commit ad970a40786d99ebecd1b3cbaab4b0f10c7c23da
parent 82554bcdd6fb55dfe4458c367f9888c0603ea4e2
Author: Anders Damsgaard <anders@adamsgaard.dk>
Date: Fri, 3 Apr 2020 10:58:22 +0200
Parse start/end time from calendar appointments, use plumb for mutt attachments
Diffstat:
3 files changed, 18 insertions(+), 164 deletions(-)
diff --git a/.config/mutt/view_attachment.sh b/.config/mutt/view_attachment.sh
@@ -1,134 +0,0 @@
-#!/bin/sh
-#
-# Author: Eric Gebhart
-#
-# Purpose: To be called by mutt as indicated by .mailcap to handle mail attachments.
-#
-# Function: Copy the given file to a temporary directory so mutt
-# Won't delete it before it is read by the application.
-#
-# Along the way, discern the file type or use the type
-# That is given.
-#
-# Finally use 'open' or 'open -a' if the third argument is
-# given.
-#
-#
-# Arguments:
-#
-# $1 is the file
-# $2 is the type - for those times when file magic isn't enough.
-# I frequently get html mail that has no extension
-# and file can't figure out what it is.
-#
-# Set to '-' if you don't want the type to be discerned.
-# Many applications can sniff out the type on their own.
-# And they do a better job of it too.
-#
-# Open Office and MS Office for example.
-#
-# $3 is open with. as in open -a 'open with this .app' foo.xls
-#
-# Examples: These are typical .mailcap entries which use this program.
-#
-# Image/JPEG; /Users/vdanen/.mutt/view_attachment %s
-# Image/PNG; /Users/vdanen/.mutt/view_attachment %s
-# Image/GIF; /Users/vdanen/.mutt/view_attachment %s
-#
-# Application/PDF; /Users/vdanen/.mutt/view_attachment %s
-#
-# #This HTML example passes the type because file doesn't always work and
-# #there aren't always extensions.
-#
-# text/html; /Users/vdanen/.mutt/view_attachment %s html
-#
-# # If your Start OpenOffice.org.app is spelled with a space like this one, <--
-# # then you'll need to precede the space with a \ . I found that too painful
-# # and renamed it with an _.
-#
-# Application/vnd.ms-excel; /Users/vdanen/.mutt/view_attachment %s "-" '/Applications/OpenOffice.org1.1.2/Start_OpenOffice.org.app'
-# Application/msword; /Users/vdanen/.mutt/view_attachment %s "-" '/Applications/OpenOffice.org1.1.2/Start_OpenOffice.org.app'
-#
-#
-# Debugging: If you have problems set debug to 'yes'. That will cause a debug file
-# be written to /tmp/mutt_attach/debug so you can see what is going on.
-#
-# See Also: The man pages for open, file, basename
-#
-
-# the tmp directory to use.
-tmpdir="$HOME/tmp/mutt_attach"
-
-# the name of the debug file if debugging is turned on.
-debug_file=$tmpdir/debug
-
-# debug. yes or no.
-debug="no"
-#debug="yes"
-
-type=$2
-open_with=$3
-
-# make sure the tmpdir exists.
-mkdir -p $tmpdir
-
-# clean it out. Remove this if you want the directory
-# to accumulate attachment files.
-rm -f $tmpdir/*
-
-# Mutt puts everything in /tmp by default.
-# This gets the basic filename from the full pathname.
-filename=`basename $1`
-
-# get rid of the extenson and save the name for later.
-file=`echo $filename | cut -d"." -f1`
-
-if [ $debug = "yes" ]; then
- echo "1:" $1 " 2:" $2 " 3:" $3 > $debug_file
- echo "Filename:"$filename >> $debug_file
- echo "File:"$file >> $debug_file
- echo "===========================" >> $debug_file
-fi
-
-# if the type is empty then try to figure it out.
-if [ -z $type ]; then
- file $1
- type=`file -bi $1 | cut -d"/" -f2 | sed 's/;.*$//'`
-fi
-
-# if the type is '-' then we don't want to mess with type.
-# Otherwise we are rebuilding the name. Either from the
-# type that was passed in or from the type we discerned.
-if [ $type = "-" ]; then
- newfile=$filename
-else
- newfile=$file.$type
-fi
-
-newfile=$tmpdir/$newfile
-
-# Copy the file to our new spot so mutt can't delete it
-# before the app has a chance to view it.
-cp $1 $newfile
-
-if [ $debug = "yes" ]; then
- echo "File:" $file "TYPE:" $type >> $debug_file
- echo "Newfile:" $newfile >> $debug_file
- echo "Open With:" $open_with >> $debug_file
-fi
-
-# If there's no 'open with' then we can let preview do it's thing.
-# Otherwise we've been told what to use. So do an open -a.
-if [ `uname | grep -i Darwin` ]; then
- opencmd=open
-else
- opencmd=xdg-open
-fi
-
-if [ -z $open_with ]; then
- echo $opencmd $newfile
- $opencmd $newfile
-else
- echo $opencmd -a "$open_with" $newfile
- $opencmd -a "$open_with" $newfile
-fi
diff --git a/.local/bin/plumb b/.local/bin/plumb
@@ -59,6 +59,10 @@ fetch() {
printf '%s' "$_o"
}
+annotate_date_string() {
+ sed 's/^\([0-9][0-9][0-9][0-9]\)\([0-1][0-9]\)\([0-3][0-9]\)/\1-\2-\3 /;s/T\([0-2][0-9]\)\([0-5][0-9]\)\([0-5][0-9]\)/\1:\2:\3/'
+}
+
handle_target() {
t="$1"
@@ -72,7 +76,15 @@ handle_target() {
text/html)
detach $BROWSER "$t";;
text/*)
- $EDITOR "$t";;
+ if [ "$(file -b "$t")" = "vCalendar calendar file" ]; then
+ starttime="$(grep -E "DTSTART.*TZID" "$t" | sed 's/.*://' | annotate_date_string )"
+ endtime="$(grep -E "DTEND.*TZID" "$t" | sed 's/.*://' | annotate_date_string )"
+ tzone="$(grep -E "DTEND.*TZID" "$t" | sed 's/.*TZID=\(.*\):.*/\1/' )"
+ notify-send "$t" "$(printf 'start: %s\nend: %s\n%s' "$starttime" "$endtime" "$tzone")"
+ termopen less "$t"
+ else
+ termopen less "$t"
+ fi;;
*shellscript*)
$EDITOR "$t";;
application/*html*)
diff --git a/.mailcap b/.mailcap
@@ -1,31 +1,7 @@
-# HTML
text/html; cp %s ~/tmp/tmp.html && $BROWSER ~/tmp/tmp.html && sleep 3 && rm ~/tmp/tmp.html; test=test -n "$DISPLAY"
text/html; w3m -I %{charset} -o display_link_number=1 -T text/html; copiousoutput; needsterminal
-
-text/plain; cat %s; copiousoutput
-text/*; $EDITOR %s; needsterminal
-
-# Office documents
-application/msword; ~/.config/mutt/view_attachment.sh '%s' "-"
-application/vnd.openxmlformats-officedocument.*; ~/.config/mutt/view_attachment.sh '%s' "-"
-
-# Images
-image/jpg; ~/.config/mutt/view_attachment.sh '%s' jpg
-image/jpeg; ~/.config/mutt/view_attachment.sh '%s' jpg
-image/pjpeg; ~/.config/mutt/view_attachment.sh '%s' jpg
-image/png; ~/.config/mutt/view_attachment.sh '%s' png
-image/gif; ~/.config/mutt/view_attachment.sh '%s' gif
-image/tiff; ~/.config/mutt/view_attachment.sh '%s' tiff
-image/svg+xml; ~/.config/mutt/view_attachment.sh '%s' svg
-
-# PDFs
-application/pdf; ~/.config/mutt/view_attachment.sh '%s' pdf
-application/postscript; ~/.config/mutt/view_attachment.sh '%s' eps
-
-# Unidentified files
-application/octet-stream; ~/.config/mutt/view_attachment.sh '%s' "-"
-application/*; ~/.config/mutt/view_attachment.sh '%s' "-"
-
-video/mp4; ~/.config/mutt/view_attachment.sh '%s' "-"
-video/avi; ~/.config/mutt/view_attachment.sh '%s' "-"
-video/quicktime; ~/.config/mutt/view_attachment.sh '%s' "-"
+text/plain; cat %s; copiousoutput; needsterminal
+text/*; plumb %s; needsterminal
+image/*; plumb %s && sleep 2
+application/*; plumb %s && sleep 2
+video/*; plumb %s && sleep 2