Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env bash
- # Check your installed feh path and change $feh_cmd to your liking
- [[ -z $1 ]] && ( echo "no arguments given" 1>&2; exit 1; )
- feh_cmd=(
- '/usr/bin/feh'
- '-sZF'
- '--scale-down'
- '--scroll-step'
- '50'
- '--no-jump-on-resort'
- '--info'
- "echo %n"
- '--draw-tinted'
- '--image-bg'
- 'black'
- '--draw-actions'
- '--slideshow-delay'
- '9999'
- '-q'
- '--no-xinerama'
- '--sort'
- 'filename'
- )
- ARG="$1"
- images=()
- DIR="$PWD"
- VALID_PATT='(image|inode)'
- if [[ "$DIR" = "" ]]
- then
- DIR="$(pwd 2> /dev/null)"
- if [[ "$DIR" = "" ]]
- then
- DIR="$HOME"
- #if [[ "$DIR" = "" ]]
- # then
- # DIR="/home/user"
- #fi
- fi
- fi
- if [[ ! -d "$(dirname "$DIR")" ]]
- then
- echo "$DIR is not a directory" 1>&2
- exit 1
- fi
- if [[ $# -gt 1 ]]
- then
- arglen=$#
- args=("$@")
- LOOPED=0
- for (( LOOPED = 0; LOOPED < arglen; LOOPED++ )); do
- if [[ ! "${args[$LOOPED]:0:1}" = "/" ]]
- then
- args[$LOOPED]="$DIR/${args[$LOOPED]}"
- fi
- MIMETYPE="$(file -b -L --mime-type "${args[$LOOPED]}")"
- if [[ $? -ne 0 ]] || [[ ! "${MIMETYPE:0:5}" =~ $VALID_PATT ]]
- then
- notify-send -i error "My Feh Image Viewer" "$(basename "${args[$LOOPED]}") is not an image\\n(""$MIMETYPE"")"
- continue
- else
- images+=("${args[$LOOPED]}")
- fi
- done
- ARG="${images[0]}"
- else
- images+=("$ARG")
- if [[ ! "${images[0]:0:1}" = "/" ]]
- then
- images[0]="$DIR/${images[0]}"
- ARG="${images[0]}"
- fi
- MIMETYPE="$(file -b -L --mime-type "${images[0]}")"
- if [[ $? -ne 0 ]] || [[ ! "${MIMETYPE:0:5}" =~ $VALID_PATT ]]
- then
- notify-send -i error "My Feh Image Viewer" "$(basename "${images[0]}") is not a valid path\\n(""$MIMETYPE"")"
- exit 1
- fi
- fi
- if [[ -f "${images[0]}" ]]
- then
- if [[ ${#images[@]} -eq 1 ]]
- then
- images=("$(dirname "$ARG")")
- fi
- "${feh_cmd[@]}" --start-at "$ARG" "${images[@]}" &
- elif [[ -d "${images[0]}" ]]
- then
- "${feh_cmd[@]}" -r "${images[@]}" &
- fi
- # overflooded opened files, kill em all
- while [[ $(pgrep -lx feh | wc -l) -gt 10 ]]
- do
- pkill -x feh
- notify-send -i error "Overflooding feh" "Closing them all"
- sleep 2s
- done
- exit $?
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement