Merge branch '2452_handle_baudrate_error'
[midnight-commander.git] / misc / ext.d / image.sh
blob46751c625e5c7b2be80645d1d23344d6a4357e98
1 #!/bin/sh
3 # $1 - action
4 # $2 - type of file
6 action=$1
7 filetype=$2
9 if [ -n "$DISPLAY" ]; then
10 [ -n "${MC_XDG_OPEN}" ] || MC_XDG_OPEN="xdg-open"
13 do_view_action() {
14 filetype=$1
16 case "${filetype}" in
17 xpm)
18 [ -n "$DISPLAY" ] && sxpm "${MC_EXT_FILENAME}"
21 if command -v exif >/dev/null 2>&1; then
22 exif "${MC_EXT_FILENAME}" 2>/dev/null
23 E=$?
24 else
25 E=1
27 if [ $E != 0 ] && command -v exiftool >/dev/null 2>&1; then
28 exiftool "${MC_EXT_FILENAME}" 2>/dev/null
30 identify "${MC_EXT_FILENAME}"
32 esac
35 do_open_action() {
36 filetype=$1
38 case "${filetype}" in
39 xbm)
40 (bitmap "${MC_EXT_FILENAME}" &)
42 xcf)
43 (gimp "${MC_EXT_FILENAME}" &)
45 svg)
46 (inkscape "${MC_EXT_FILENAME}" &)
49 if [ -n "$DISPLAY" ]; then
50 if command -v geeqie >/dev/null 2>&1; then
51 (geeqie "${MC_EXT_FILENAME}" &)
52 else
53 (gqview "${MC_EXT_FILENAME}" &)
55 # no backgrounding for console viewers
56 elif command -v fim >/dev/null 2>&1; then
57 fim "${MC_EXT_FILENAME}"
58 elif command -v fbi >/dev/null 2>&1; then
59 fbi "${MC_EXT_FILENAME}"
60 elif command -v zgv >/dev/null 2>&1; then
61 zgv "${MC_EXT_FILENAME}"
62 # run-mailcap as a last resort
63 elif command -v see >/dev/null 2>&1; then
64 (see "${MC_EXT_FILENAME}" &)
67 esac
70 case "${action}" in
71 view)
72 do_view_action "${filetype}"
74 open)
75 ("${MC_XDG_OPEN}" "${MC_EXT_FILENAME}" >/dev/null 2>&1) || \
76 do_open_action "${filetype}"
80 esac