image.sh 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. #!/bin/sh
  2. # $1 - action
  3. # $2 - type of file
  4. action=$1
  5. filetype=$2
  6. [ -n "${MC_XDG_OPEN}" ] || MC_XDG_OPEN="xdg-open"
  7. do_view_action() {
  8. filetype=$1
  9. case "${filetype}" in
  10. xpm)
  11. [ -n "$DISPLAY" ] && sxpm "${MC_EXT_FILENAME}"
  12. ;;
  13. *)
  14. if which exif >/dev/null 2>&1; then
  15. exif "${MC_EXT_FILENAME}" 2>/dev/null
  16. E=$?
  17. else
  18. E=1
  19. fi
  20. if [ $E != 0 ] && which exiftool >/dev/null 2>&1; then
  21. exiftool "${MC_EXT_FILENAME}" 2>/dev/null
  22. fi
  23. identify "${MC_EXT_FILENAME}"
  24. ;;
  25. esac
  26. }
  27. do_open_action() {
  28. filetype=$1
  29. case "${filetype}" in
  30. xbm)
  31. (bitmap "${MC_EXT_FILENAME}" &)
  32. ;;
  33. xcf)
  34. (gimp "${MC_EXT_FILENAME}" &)
  35. ;;
  36. svg)
  37. (inkscape "${MC_EXT_FILENAME}" &)
  38. ;;
  39. *)
  40. if [ -n "$DISPLAY" ]; then
  41. if which geeqie >/dev/null 2>&1; then
  42. (geeqie "${MC_EXT_FILENAME}" &)
  43. else
  44. (gqview "${MC_EXT_FILENAME}" &)
  45. fi
  46. elif which see >/dev/null 2>&1; then
  47. (see "${MC_EXT_FILENAME}" &)
  48. else
  49. (zgv "${MC_EXT_FILENAME}" &)
  50. fi
  51. ;;
  52. esac
  53. }
  54. case "${action}" in
  55. view)
  56. do_view_action "${filetype}"
  57. ;;
  58. open)
  59. ("${MC_XDG_OPEN}" "${MC_EXT_FILENAME}" >/dev/null 2>&1) || \
  60. do_open_action "${filetype}"
  61. ;;
  62. *)
  63. ;;
  64. esac