My build of nnn with minor changes
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 
 
 
 
 

71 wiersze
1.9 KiB

  1. #!/usr/bin/env sh
  2. # Description: Open images in hovered directory and thumbnails
  3. # open hovered image in sxiv or viu and browse other images in the directory
  4. # Dependencies: imv (https://github.com/eXeC64/imv) or,
  5. # sxiv (https://github.com/muennich/sxiv) or,
  6. # viu (https://github.com/atanunq/viu), less
  7. #
  8. # Shell: POSIX compliant
  9. # Author: Arun Prakash Jana
  10. abspath() {
  11. case "$1" in
  12. /*) printf "%s\n" "$1";;
  13. *) printf "%s\n" "$PWD/$1";;
  14. esac
  15. }
  16. listimages() {
  17. find -L "$(dirname "$target")" -maxdepth 1 -type f -iregex \
  18. '.*\(jpe?g\|bmp\|webp\|png\|gif\)$' -print0 | sort -z
  19. }
  20. view_dir() {
  21. target="$(abspath "$2")"
  22. count="$(listimages | grep -a -m 1 -ZznF "$target" | cut -d: -f1)"
  23. if [ -n "$count" ]; then
  24. if [ "$1" = 'sxiv' ]; then
  25. listimages | xargs -0 "$1" -an "$count" --
  26. else
  27. listimages | xargs -0 "$1" -n "$count" --
  28. fi
  29. else
  30. shift
  31. "$1" -- "$@" # fallback
  32. fi
  33. }
  34. if [ -z "$1" ] || ! [ -s "$1" ]; then
  35. printf "empty file"
  36. read -r _
  37. exit 1
  38. fi
  39. if uname | grep -q "Darwin"; then
  40. if [ -f "$1" ]; then
  41. open "$1" >/dev/null 2>&1 &
  42. fi
  43. # `imvr` is often callable as `imv` on Linux distros
  44. # You might need to change the reference below
  45. elif which imvr >/dev/null 2>&1; then
  46. if [ -f "$1" ]; then
  47. view_dir imvr "$1" >/dev/null 2>&1 &
  48. elif [ -d "$1" ] || [ -h "$1" ]; then
  49. imvr "$1" >/dev/null 2>&1 &
  50. fi
  51. elif which sxiv >/dev/null 2>&1; then
  52. if [ -f "$1" ]; then
  53. view_dir sxiv "$1" >/dev/null 2>&1 &
  54. elif [ -d "$1" ] || [ -h "$1" ]; then
  55. sxiv -aqt "$1" >/dev/null 2>&1 &
  56. fi
  57. elif which viu >/dev/null 2>&1; then
  58. viu -n "$1" | less -R
  59. else
  60. printf "Please install imv/sxiv/viu and check their callable names match the plugin source"
  61. read -r _
  62. exit 2
  63. fi