Advertisement
Guest User

Untitled

a guest
Jul 7th, 2015
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.99 KB | None | 0 0
  1. #!/usr/bin/env bash
  2.  
  3. # Check your installed feh path and change $feh_cmd to your liking
  4.  
  5. [[ -z $1 ]] && ( echo "no arguments given" 1>&2; exit 1; )
  6.  
  7. feh_cmd=(
  8. '/usr/bin/feh'
  9. '-sZF'
  10. '--scale-down'
  11. '--scroll-step'
  12. '50'
  13. '--no-jump-on-resort'
  14. '--info'
  15. "echo %n"
  16. '--draw-tinted'
  17. '--image-bg'
  18. 'black'
  19. '--draw-actions'
  20. '--slideshow-delay'
  21. '9999'
  22. '-q'
  23. '--no-xinerama'
  24. '--sort'
  25. 'filename'
  26. )
  27. ARG="$1"
  28. images=()
  29. DIR="$PWD"
  30. VALID_PATT='(image|inode)'
  31.  
  32. if [[ "$DIR" = "" ]]
  33. then
  34. DIR="$(pwd 2> /dev/null)"
  35. if [[ "$DIR" = "" ]]
  36. then
  37. DIR="$HOME"
  38. #if [[ "$DIR" = "" ]]
  39. # then
  40. # DIR="/home/user"
  41. #fi
  42. fi
  43. fi
  44.  
  45. if [[ ! -d "$(dirname "$DIR")" ]]
  46. then
  47. echo "$DIR is not a directory" 1>&2
  48. exit 1
  49. fi
  50.  
  51. if [[ $# -gt 1 ]]
  52. then
  53. arglen=$#
  54. args=("$@")
  55. LOOPED=0
  56. for (( LOOPED = 0; LOOPED < arglen; LOOPED++ )); do
  57. if [[ ! "${args[$LOOPED]:0:1}" = "/" ]]
  58. then
  59. args[$LOOPED]="$DIR/${args[$LOOPED]}"
  60. fi
  61. MIMETYPE="$(file -b -L --mime-type "${args[$LOOPED]}")"
  62. if [[ $? -ne 0 ]] || [[ ! "${MIMETYPE:0:5}" =~ $VALID_PATT ]]
  63. then
  64. notify-send -i error "My Feh Image Viewer" "$(basename "${args[$LOOPED]}") is not an image\\n(""$MIMETYPE"")"
  65. continue
  66. else
  67. images+=("${args[$LOOPED]}")
  68. fi
  69. done
  70. ARG="${images[0]}"
  71. else
  72. images+=("$ARG")
  73. if [[ ! "${images[0]:0:1}" = "/" ]]
  74. then
  75. images[0]="$DIR/${images[0]}"
  76. ARG="${images[0]}"
  77. fi
  78. MIMETYPE="$(file -b -L --mime-type "${images[0]}")"
  79. if [[ $? -ne 0 ]] || [[ ! "${MIMETYPE:0:5}" =~ $VALID_PATT ]]
  80. then
  81. notify-send -i error "My Feh Image Viewer" "$(basename "${images[0]}") is not a valid path\\n(""$MIMETYPE"")"
  82. exit 1
  83. fi
  84. fi
  85.  
  86. if [[ -f "${images[0]}" ]]
  87. then
  88. if [[ ${#images[@]} -eq 1 ]]
  89. then
  90. images=("$(dirname "$ARG")")
  91. fi
  92. "${feh_cmd[@]}" --start-at "$ARG" "${images[@]}" &
  93. elif [[ -d "${images[0]}" ]]
  94. then
  95. "${feh_cmd[@]}" -r "${images[@]}" &
  96. fi
  97.  
  98. # overflooded opened files, kill em all
  99. while [[ $(pgrep -lx feh | wc -l) -gt 10 ]]
  100. do
  101. pkill -x feh
  102. notify-send -i error "Overflooding feh" "Closing them all"
  103. sleep 2s
  104. done
  105.  
  106. exit $?
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement