image.sh 1.7 KB

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