/
open
executable file
·47 lines (40 loc) · 1.23 KB
/
open
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/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"