sxiv_browser supports archives

This commit is contained in:
lanxu 2018-10-20 19:13:27 +03:00
parent 65994d552d
commit f912d3d912

View File

@ -46,10 +46,35 @@ listfiles () {
ls -dv "$(dirname "$target")"/* | egrep '.*(jpe?g|bmp|png|gif)$' | awk '{print}' ORS='\0' ls -dv "$(dirname "$target")"/* | egrep '.*(jpe?g|bmp|png|gif)$' | awk '{print}' ORS='\0'
} }
isarchive () {
FILE_PATH="${1}"
FILE_EXTENSION="${FILE_PATH##*.}"
FILE_EXTENSION_LOWER="${FILE_EXTENSION,,}"
MIMETYPE="$(xdg-mime query filetype "$1" )"
case "${FILE_EXTENSION_LOWER}" in
a|ace|alz|arc|arj|bz|bz2|cab|cpio|deb|gz|jar|lha|lz|lzh|lzma|lzo|\
rar|rpm|rz|t7z|tar|tbz|tbz2|tgz|tlz|txz|tZ|tzo|war|xpi|xz|Z|zip|7z)
return 0
esac
case "${FILE_EXTENSION_LOWER}" in
cbz|cbr)
return 0
esac
return -1
}
target="$(abspath "$1")" target="$(abspath "$1")"
if isarchive "$target"; then
TEMPDIR=$(mktemp -d)
atool --quiet --extract-to=$TEMPDIR --each -- "$target" 2&> /dev/null
find $TEMPDIR/**/* -print0 | xargs -0 -n 1 -Ifoo cp "foo" $TEMPDIR/
target=$TEMPDIR/.
fi
count="$(listfiles | grep -m 1 -ZznF "$target" | cut -d: -f1)" count="$(listfiles | grep -m 1 -ZznF "$target" | cut -d: -f1)"
if [ -n "$count" ]; then if [ -n "$count" ]; then
listfiles | xargs -s 1280000 -0 sxiv -an "$count" -- listfiles | xargs -s 1280000 -0 sxiv -an "$count" --
else else
sxiv -- "$@" # fallback sxiv -- "$target" # fallback
fi fi