[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [gcmd-dev] Umime
From: |
Magnus Stålnacke |
Subject: |
Re: [gcmd-dev] Umime |
Date: |
Sat, 25 Mar 2006 01:29:54 +0100 |
User-agent: |
Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.7.12) Gecko/20051003 |
Magnus Stålnacke wrote:
I have started to develop a shellscript for managing
mime types, attached is what i have done so far...
Here comes version 0.2 of my script.
Now it uses ncurses dialog and handles also the
default list (a tricky one..). It is not beautiful
written (i do not know how), it is a mess, has probably
some bugs and so on. So, back up your .local/share dir
before trying..
#!/bin/bash
#
# Umime - a script for chosing prefered applications.
# Written by Magnus Stålnacke (jemamo at telia.com)
# Version 0.2 (25 Mars 2006)
#
# TODO
# Add "runs in terminal" option
#
export LANG=en_US.utf8
XDG_DATA_DIRS=$HOME/.local/share
DEFAULT=$XDG_DATA_DIRS/applications/defaults.list
G_CACHE=/usr/share/applications/mimeinfo.cache
U_CACHE=$XDG_DATA_DIRS/applications/mimeinfo.cache
MTPE=`file -i $1 | awk '{print $2}'`
EXT=usercreated.desktop
function modmime(){
GLOB_USER=`cat $U_CACHE $G_CACHE`
USER_APP="$XDG_DATA_DIRS/applications/$APP-$EXT"
if echo "$GLOB_USER" | grep "$MTPE" | grep -q "$APP"
then
M_MESSAGE="The mime type: $MTPE is alredy assigned to: $APP"
else
if [ -e "$USER_APP" ]
then
cat $USER_APP | sed "s|MimeType=|MimeType=$MTPE;|g" > $USER_APP
M_MESSAGE="The mime type: $MTPE is now added to: $APP"
else
echo "[Desktop Entry]" > $USER_APP
echo "Encoding=UTF-8" >> $USER_APP
echo "Name=$NME" >> $USER_APP
echo "MimeType=$MTPE;" >> $USER_APP
echo "Exec='$CMD'" >> $USER_APP
echo "Type=Application" >> $USER_APP
echo "Terminal=false" >> $USER_APP
echo "NoDisplay=true" >> $USER_APP
M_MESSAGE="The application: $APP is now registered to handle: $MTPE"
fi
export XDG_DATA_DIRS
update-desktop-database -q
fi
}
function deflist (){
G_AVAIL=`grep "$MTPE" $G_CACHE | sed -e 's/.*=//g;s/;$//g;s/;/\n/g'`
U_AVAIL=`grep "$MTPE" $U_CACHE | sed -e 's/.*=//g;s/;$//g;s/;/\n/g'`
for i in $G_AVAIL; do
NM=`grep "^Name=" /usr/share/applications/$i | sed -e "s/Name=//g;s/ /_/g"`
echo "$NM $i off" >> /tmp/avail
done
for i in $U_AVAIL; do
NM=`grep "^Name=" $XDG_DATA_DIRS/applications/$i | sed 's/Name=//g;s/ /_/g'`
echo "$NM $i off" >> /tmp/avail
done
#
# Change no to yes for the alredy set user default app.
#
if grep -q "$MTPE" $DEFAULT
then
DEF_APP=`grep "$MTPE" $DEFAULT | sed "s|$MTPE=||g"`
cat /tmp/avail | sed "s|$DEF_APP off|$DEF_APP on|g" > /tmp/avail
fi
#
dialog --radiolist "Please select" 20 74 11 `cat /tmp/avail` 2> /tmp/chosen
retval=$?
choice=`cat /tmp/chosen`
clear
case $retval in
0)
DEF_CH=`grep "$choice" /tmp/avail | awk '{print $2}'`
if grep -q "$MTPE" $DEFAULT
then
cat $DEFAULT | sed "s|$MTPE=.*|$MTPE=$DEF_CH|" > $DEFAULT
DEF_MESSAGE="Default application to handle $MTPE is changed to $choice"
else
echo "$MTPE=$DEF_CH" >> $DEFAULT
DEF_MESSAGE="Default application to handle $MTPE is set to $choice"
fi;;
1)
echo "Cancel pressed.";;
255)
echo "ESC pressed.";;
esac
rm -f /tmp/avail
rm -f /tmp/chosen
}
#
# Ask the user for app. command
#
function chcmd (){
dialog --inputbox "Write the command to start the application $NME" 20 74 2>
/tmp/chosen
APP=`cat /tmp/chosen`
rm -f /tmp/chosen
# Check command
if which $APP >&/dev/null
then
CMD=`which $APP`
modmime
else
dialog --inputbox "No such command in path, try assign command with full
path" 20 74 2> /tmp/chosen
APP=`cat /tmp/chosen`
rm -f /tmp/chosen
fi
deflist
}
#
# Ask the user for app.Name
#
dialog --inputbox "Write the name of the application you wish to register \
as able to handle the mime type: $MTPE, or press cancel if you only want to \
set the default application to handle this mime type." 20 74 2> /tmp/chosen
if [ -s /tmp/chosen ]
then
NME=`cat /tmp/chosen`
chcmd
rm -f /tmp/chosen
else
deflist
fi
#
echo "** $M_MESSAGE"
echo "--"
echo "** $DEF_MESSAGE"
Re: [gcmd-dev] Python plugins (was: archive browser plugin), Piotr Eljasiak, 2006/03/27
Re: [gcmd-dev] Umime,
Magnus Stålnacke <=