Permalink
Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
executable file 48 lines (40 sloc) 1.23 KB
#!/bin/bash
#same as xdg-open, but forces xdg's implementation, which blocks, unlike gnome-open. Huge hack, of course
exit_success()
{
if [ $# -gt 0 ]; then
echo "$@"
echo
fi
exit 0
}
first_word()
{
read first rest
echo "$first"
}
open_generic_xdg_mime()
{
filetype=`xdg-mime query filetype "$1" | sed "s/;.*//"`
default=`xdg-mime query default "$filetype"`
if [ -n "$default" ] ; then
xdg_user_dir="$XDG_DATA_HOME"
[ -n "$xdg_user_dir" ] || xdg_user_dir="$HOME/.local/share"
xdg_system_dirs="$XDG_DATA_DIRS"
[ -n "$xdg_system_dirs" ] || xdg_system_dirs=/usr/local/share/:/usr/share/
for x in `echo "$xdg_user_dir:$xdg_system_dirs" | sed 's/:/ /g'`; do
local file="$x/applications/$default"
if [ -r "$file" ] ; then
command="`grep -E "^Exec(\[[^]=]*])?=" "$file" | cut -d= -f 2- | first_word`"
command_exec=`which $command 2>/dev/null`
if [ -x "$command_exec" ] ; then
$command_exec "$1"
if [ $? -eq 0 ]; then
exit_success
fi
fi
fi
done
fi
}
open_generic_xdg_mime "$1"