diff options
| author | yuzu-eva <cafebabe@disroot.org> | 2025-05-08 14:01:37 +0200 |
|---|---|---|
| committer | yuzu-eva <cafebabe@disroot.org> | 2025-05-08 14:01:37 +0200 |
| commit | ef7c1605a027b52bbff1b01ea693b60f53fa3a71 (patch) | |
| tree | 1089334258aefbd459d18cf6968e78f1194739b0 /iv | |
initial commit
Diffstat (limited to 'iv')
| -rwxr-xr-x | iv | 36 |
1 files changed, 36 insertions, 0 deletions
@@ -0,0 +1,36 @@ +#!/usr/bin/env bash + +TMPDIR="${TMPDIR:-/tmp}" +tmp="$TMPDIR/nsxiv_rifle_$$" + +is_img_extension () { + grep -iE '\.(jpe?g|png|gif|svg|webp|tiff|heif|avif|ico|bmp)$' +} + +listfiles () { + find -L "${1%/*}" \( ! -path "${1%/*}" -prune \) -type f -print | + is_img_extension | sort | tee "$tmp" +} + +open_img () { + # Only go through listfiles() if the file has a valid img extension + if echo "$1" | is_img_extension >/dev/null 2>&1; then + trap 'rm -f $tmp' EXIT + count="$(listfiles "$1" | grep -nF "$1")" + fi + if [ -n "$count" ]; then + nsxiv -o -i -a -n "${count%%:*}" -- < "$tmp" + else + # Fallback in case the file didn't have a valid extension, or we + # couldn't find it inside the list + nsxiv -- "$@" + fi +} + +[ "$1" = '--' ] && shift +case "$1" in + "") echo "Usage: ${0##*/} PICTURES" >&2; exit 1 ;; + /*) open_img "$1" ;; + "~"/*) open_img "$HOME/${1#"~"/}" ;; + *) open_img "$PWD/$1" ;; +esac |
