diff options
| author | 2020-03-03 06:16:52 +0530 | |
|---|---|---|
| committer | 2020-03-03 06:16:52 +0530 | |
| commit | 4aa12a2dfb2f14511f9cd152c10a5b0d1947b078 (patch) | |
| tree | 5f514ce1fb22a124b34b5c0f2b1c79deed93a18f /plugins/imgview | |
| parent | 0941e511e404684fba13d358c2c7b4d6581d683b (diff) | |
| download | nnn-4aa12a2dfb2f14511f9cd152c10a5b0d1947b078.tar.gz | |
sxiv: load dir along with file
Diffstat (limited to 'plugins/imgview')
| -rwxr-xr-x | plugins/imgview | 27 |
1 files changed, 25 insertions, 2 deletions
diff --git a/plugins/imgview b/plugins/imgview index dc4d3a4..9370ae5 100755 --- a/plugins/imgview +++ b/plugins/imgview @@ -6,6 +6,29 @@ # Shell: POSIX compliant # Author: Arun Prakash Jana +abspath() { + case "$1" in + /*) printf "%s\n" "$1";; + *) printf "%s\n" "$PWD/$1";; + esac +} + +listimages() { + find -L "$(dirname "$target")" -maxdepth 1 -type f -iregex \ + '.*\(jpe?g\|bmp\|png\|gif\)$' -print0 | sort -z +} + +sxiv_view_dir() { + target="$(abspath "$1")" + count="$(listimages | grep -a -m 1 -ZznF "$target" | cut -d: -f1)" + + if [ -n "$count" ]; then + listimages | xargs -0 sxiv -n "$count" -- + else + sxiv -- "$@" # fallback + fi +} + if [ -z "$1" ] || ! [ -s "$1" ]; then printf "empty file" read -r _ @@ -14,9 +37,9 @@ fi if command -v sxiv >/dev/null 2>&1; then if [ -f "$1" ]; then - sxiv -q "$1" "$PWD" + sxiv_view_dir "$1" >/dev/null 2>&1 & elif [ -d "$1" ] || [ -h "$1" ]; then - sxiv -qt "$1" + sxiv -qt "$1" >/dev/null 2>&1 & fi elif command -v viu >/dev/null 2>&1; then viu -n "$1" | less -R |