Hi!
I've just wrote a script which generates a /etc/mc/mc.ext file using
information from mime.types and mailcap files.
I found it very useful. It takes a list of extensions from mime.types
then check if in mailcap we've got support for that extension.
If yes it put this extension do mc.ext and assings action (run-mailcap).
I think, it's very good to automate generating mc.ext file.
When user install software that provides /etc/mailcap record it will be
automagically added to mc.ext.
Please, share with me with your opinions.
PS.
I'm not good in writing shell scripts, and this script is running very
slow. If you can, please improve it.
Regards.
Marcin
--
.---, --: mcINEK :--
/ ,. \ ' T h e O w l s a r e n o t
| | ; ; W h a t T h e y S e e m . . . '
\ `._ / wrote on Debian GNU/Linux SID
# !/bin/bash
# This script converts /etc/mailcap records to Midnigh Commander
# configuration file /etc/mc/mc.ext.
#
# Author: mcINEK <kaioshin@gazeta.pl>
mailcap_file="/etc/mailcap"
mime_types_file="/etc/mime.types"
mc_ext_file="mc.ext" # just debug, change it to /etc/mc/mc.ext
tmp_file="/tmp/mc.ext.tmp"
if [ ! -e $mailcap_file ]; then
echo "Can't find $mailcap_file"
echo "Be sure that mail-support package is installed."
exit
fi
echo "Generating $mc_ext_file ..."
cat $mime_types_file | sed '/^#.*/d' | sed '/^$/d' > $tmp_file
{
echo "# This file is generated by a script."
echo
} > $mc_ext_file
while read line; do
mime_type=`echo $line | awk -F' ' '{ print $1 }'`
mime_ext=`echo $line | awk -F' ' '{ for(i=2;i<=NF;i++) {print $i} }'`
ext_count=`echo $mime_ext | awk '{ print NF }'`
if [ $ext_count == "0" ]; then
continue
fi
is_in_mailcap=`grep "$mime_type" $mailcap_file`
if [ "$is_in_mailcap" == "" ]; then
echo -n "."
continue
fi
# put a mime type into file (optional)
# you can comment it out
echo "# $mime_type" >> $mc_ext_file
if [ $ext_count == "1" ]; then
echo "shell/.$mime_ext" >> $mc_ext_file
else
for ((i=0; i<$ext_count; i++)); do
mime_ext=`echo $mime_ext | sed 's/ /|/'`
done
echo "regex/\\.($mime_ext)\$" >> $mc_ext_file
fi
echo " Open=run-mailcap $mime_type:%f" >> $mc_ext_file
echo >> $mc_ext_file
echo -n "o"
done < $tmp_file
rm $tmp_file
echo
Attachment:
signature.asc
Description: PGP signature