blob: 0e8e210c7faf2f55d5ca4c2e3e1f804112e5e113 (
plain)
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
#!/bin/sh
# Inspired by https://github.com/salman-abedin/launch.sh
# Launches files based on their mimetypes
# Use option -s devour to swallow or -s " " to open normally from terminal
# Use -t to specify mimetype
# Requires: dmenu_path or similar (fallback)
# environment variables for default programs need to be set
# (I might remove this requirement at some point)
menu=${MENU:-dmenu}
while getopts "s:t:" opt; do
case "$opt" in
s)
launcher="$OPTARG"
;;
t)
mimetype="$OPTARG"
;;
esac
done
shift `expr $OPTIND - 1`
[ -z "$launcher" ] && launcher="spawn"
[ -z "$mimetype" ] && mimetype="$(file --mime-type "$1" -bL)"
[ -d "$1" ] && $launcher $XFILEMANAGER "$1" && exit 0
[ ! -f "$1" ] && echo "$1: bad argument" && exit 1
case "$mimetype" in
video/*)
$launcher $VIDEOPLAYER "$1"
;;
audio/*)
$launcher $MUSICPLAYER "$1"
;;
application/pdf | application/postscript | image/vnd.djvu)
$launcher $VIEWER "$1"
;;
image/*)
$launcher $IMAGEVIEWER "$1"
;;
application/msword | \
application/vnd.oasis.opendocument.text | text/rtf | \
application/vnd.openxmlformats-officedocument.wordprocessingml.*)
$launcher $TEXTDOCUMENT "$1"
;;
application/ms-excel | application/vnd.oasis.opendocument.spreadsheet | \
text/rtf | application/vnd.openxmlformats-officedocument.spreadsheetml.*)
$launcher $SPREADSHEET "$1"
;;
text/html | text/enriched)
$launcher $HTMLVIEWER "$1"
;;
text/*)
$launcher $XEDITOR "$1"
;;
application/zip)
unzip "$1"
;;
application/x-rar-compressed)
unrar "$1"
;;
application/x-archive | application/x-tar | \
application/x-bzip2 | application/gzip | application/x-lzip | \
application/x-lzma | application/x-xz | application/x-gtar)
tar -tavf "$1"
;;
application/java-archive)
java -jar "$1"
;;
*)
prog=$(dmenu_path | $menu -p "How to open $1 ?")
if [ -n "$prog" ]; then
$launcher $prog "$1"
else
exit 1
fi
;;
esac
|