#!/bin/sh
# (c) 2020 Senri Software
#
# Permission to use, copy, modify, and distribute this software for any purpose
# with or without fee is hereby granted.
#
# The software is provided "as is" and the author disclaims all warranties with
# regard to this software including all implied warranties of merchantability
# and fitness. In no event shall the author be liable for any special, direct,
# indirect, or consequential damages or any damages whatsoever resulting from
# loss of use, data or profits, whether in an action of contract, negligence or
# other tortious action, arising out of or in connection with the use or
# performance of this software.
for file; do
 archive=$(readlink -f "$file")
 filename=$(basename "$archive")
 md5=$(echo $archive | md5sum | awk '{print $1; exit}')
 if [ ! -e /tmp/archive-$USER/$md5 ]; then
   mkdir -p /tmp/archive-$USER/$md5/"$filename"
   archivemount -o nobackup "$archive" /tmp/archive-$USER/$md5/"$filename"
 fi
 xdg-open /tmp/archive-$USER/$md5/"$filename"
done