blob: 322ffd9772ca385099c71c59dea2716e304a6a60 (
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
|
#!/bin/sh
# Inspired by https://github.com/salman-abedin/launch.sh
# Launches files based on their mimetypes
# Usage: open-file [-m menu] [-s launcher] [-t mimetype] [files...]
# Requires: dmenu_path or similar (fallback), dmenu-filepicker
menu="dmenu -i -l 15"
# Change default apps here
video="mpv"
music="mpv --player-operation-mode=pseudo-gui"
pdf="zathura"
img="imv"
word="libreoffice"
sheet="libreoffice"
html="firefox --new-window"
xedit="xedit"
openfile() {
f="$@"
localmime="$mimetype"
[ ! -f "$f" ] && echo "$f: bad argument" && exit 1
[ -z "$mimetype" ] && localmime="$(file --mime-type "$f" -bL)"
prog=""
case "$localmime" in
video/*)
prog="$video"
;;
audio/*)
prog="$music"
;;
application/pdf | application/postscript | image/vnd.djvu)
prog="$pdf"
;;
image/*)
prog="$img"
;;
application/msword | \
application/vnd.oasis.opendocument.text | text/rtf | \
application/vnd.openxmlformats-officedocument.wordprocessingml.*)
prog="$word"
;;
application/ms-excel | application/vnd.oasis.opendocument.spreadsheet | \
text/rtf | application/vnd.openxmlformats-officedocument.spreadsheetml.*)
prog="$sheet"
;;
text/html | text/enriched)
prog="$html"
;;
text/*)
prog="$xedit"
;;
application/zip)
prog="unzip"
;;
application/x-rar-compressed)
prog="unrar"
;;
application/x-archive | application/x-tar | \
application/x-bzip2 | application/gzip | application/x-lzip | \
application/x-lzma | application/x-xz | application/x-gtar)
prog="tar -tavf"
;;
application/java-archive)
prog="java -jar"
;;
*)
prog=$(dmenu_path | $menu -p "How to open $f ?")
;;
esac
if [ -n "$prog" ]; then
$launcher $prog "$f"
else
exit 1
fi
}
while getopts "m:s:t:" opt; do
case "$opt" in
m)
menu="$OPTARG"
;;
s)
launcher="$OPTARG"
;;
t)
mimetype="$OPTARG"
;;
esac
done
shift `expr $OPTIND - 1`
toopen=$@
if [ -n "$1" ]; then
while [ -n "$1" ]; do
openfile "$1" &
shift
done
else
dmenu-filepicker -m "$menu" | while read line; do
openfile "$line" &
done
fi
|