-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmimeapps.sh
executable file
·76 lines (68 loc) · 1.46 KB
/
mimeapps.sh
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
#!/usr/bin/env bash
###
### mimeapps.sh — Choose an appllication able to open the given file, or open
### it with the given application
###
### Usage:
### mimeapp.sh [-m|--mime-type mime/type] <file> [<app name>]
###
### Options:
### <file> File to open
### <app name> App to use for openning the file
### --mime-type|m specify the file mime-type
### -h Show this message.
set -e
set -o errexit
set -o nounset
set -o pipefail
if [[ "${TRACE-0}" == "1" ]]; then
set -o xtrace
fi
help() {
sed -rn 's/^### ?//;T;p' "$0"
}
SCRIPTPATH=$(realpath "$(dirname "$0")")
help() {
sed -rn 's/^### ?//;T;p' "$0"
}
TEMP=$(getopt -o 'hm:' --long 'help,mime-type:' -n 'ropen' -- "$@")
if [ $? -ne 0 ]; then
echo 'Terminating...' >&2
exit 1
fi
# Note the quotes around "$TEMP": they are essential!
eval set -- "$TEMP"
unset TEMP
keep=""
mimetype=""
while true; do
case "$1" in
'-m'|'--mime-type')
mimetype="--mime-type $2"
shift 2; continue
;;
'-h'|'--help')
help
exit 0
;;
'--')
shift ; break
;;
*)
echo 'Internal error!' >&2
exit 1
;;
esac
done
main() {
export ROFI_RETV
#export XDG_DATA_DIRS=/home/clabaut/.local/share/applications:/var/lib/flatpak/exports/share:/usr/local/share:/usr/share
#env > /tmp/log
if [[ "$#" -lt 2 ]]
then
"$SCRIPTPATH/mimeapps" $mimetype "$1"
else
coproc ( "$SCRIPTPATH/mimeapps" $mimetype "$1" "$2" > /dev/null 2>&1 )
fi
}
main "$@"