web.sh 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. html)
  11. links -dump "${MC_EXT_FILENAME}" 2>/dev/null || \
  12. w3m -dump "${MC_EXT_FILENAME}" 2>/dev/null || \
  13. lynx -dump -force_html "${MC_EXT_FILENAME}" 2>/dev/null ||
  14. cat "${MC_EXT_FILENAME}"
  15. ;;
  16. *)
  17. ;;
  18. esac
  19. }
  20. do_open_action() {
  21. filetype=$1
  22. case "${filetype}" in
  23. html)
  24. (if [ -n "$DISPLAY" ]; then
  25. for browser in gnome-moz-remote mozilla firefox chromium google-chrome konqueror brave-browser opera open ; do
  26. if command -v "${browser}" 1>&2 ; then
  27. "${browser}" file://"${MC_EXT_CURRENTDIR}"/"${MC_EXT_BASENAME}" 1>&2 &
  28. break
  29. fi
  30. done
  31. else
  32. elinks "${MC_EXT_FILENAME}" || \
  33. links "${MC_EXT_FILENAME}" || \
  34. lynx -force_html "${MC_EXT_FILENAME}" || \
  35. ${PAGER:-more} "${MC_EXT_FILENAME}"
  36. fi) 2>/dev/null
  37. ;;
  38. *)
  39. ;;
  40. esac
  41. }
  42. case "${action}" in
  43. view)
  44. do_view_action "${filetype}"
  45. ;;
  46. open)
  47. ("${MC_XDG_OPEN}" "${MC_EXT_FILENAME}" >/dev/null 2>&1) || \
  48. do_open_action "${filetype}"
  49. ;;
  50. *)
  51. ;;
  52. esac