From 3bcfa310cca3d8f6d37aee2dec9f4e7f41c99ee7 Mon Sep 17 00:00:00 2001 From: Marty Oehme Date: Sun, 8 Jan 2023 17:19:47 +0100 Subject: [PATCH] Add automatic guessing of image viewer application --- uoeia | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/uoeia b/uoeia index 5b284a8..0784013 100755 --- a/uoeia +++ b/uoeia @@ -5,7 +5,7 @@ show_usage() { Usage: uoeia [OPTION]... [FILE|URL] -Displays the specified image using the nsxiv program, or an image viewer of your choice. +Displays the specified image using your preferred image viewer. Can open remote urls of individual images, galleries, as well as local files at the same time. Uses gallery-dl for remote gallery opening - so if gallery-dl can open it, so can your image viewer. @@ -33,9 +33,6 @@ Examples: " } -cache_dir="$(mktemp -d)" -imageviewer=nsxiv - die() { [ -n "$1" ] && printf '%s\n' "$*" >&2 exit 1 @@ -88,6 +85,20 @@ dereference() { echo "$output" } +get_imageviewer() { + if command -v nsxiv 1>/dev/null 2>&1; then + echo nsxiv + elif command -v sxiv 1>/dev/null 2>&1; then + echo sxiv + elif command -v feh 1>/dev/null 2>&1; then + echo feh + elif command -v imv 1>/dev/null 2>&1; then + echo imv + elif command -v vimiv 1>/dev/null 2>&1; then + echo vimiv + fi +} + main() { command -v "${imageviewer}" 1>/dev/null 2>&1 || die "Error: Opening images in ${imageviewer} requires ${imageviewer} to be installed and and on the path." @@ -107,8 +118,11 @@ main() { ${imageviewer} "$cache_dir" } +cache_dir="$(mktemp -d)" +imageviewer="$(get_imageviewer)" gal_args=() replacements=() + while [[ $# -gt 0 ]]; do case "$1" in -h | --help)