From c3f1568d3aff379eb4f1524b112ccc6d46142034 Mon Sep 17 00:00:00 2001 From: Marty Oehme Date: Sun, 8 Jan 2023 17:19:24 +0100 Subject: [PATCH 1/5] Improve error messages --- uoeia | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/uoeia b/uoeia index 0e179f6..5b284a8 100755 --- a/uoeia +++ b/uoeia @@ -89,10 +89,10 @@ dereference() { } main() { - command -v "${imageviewer}" 1>/dev/null 2>&1 || die "Opening images in ${imageviewer} requires ${imageviewer} to be installed and and on the path." + command -v "${imageviewer}" 1>/dev/null 2>&1 || die "Error: Opening images in ${imageviewer} requires ${imageviewer} to be installed and and on the path." trap cleanup EXIT - [ -d "$cache_dir" ] || mkdir -p -- "$cache_dir" || die + [ -d "$cache_dir" ] || mkdir -p -- "$cache_dir" || die "Error: Can not create cache directory {$cache_dir}" im_number=1 while [ -n "$1" ]; do case "$1" in From 3bcfa310cca3d8f6d37aee2dec9f4e7f41c99ee7 Mon Sep 17 00:00:00 2001 From: Marty Oehme Date: Sun, 8 Jan 2023 17:19:47 +0100 Subject: [PATCH 2/5] 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) From 94a2dfcef78f43f4e3442bb88b2cc3bfc793ee2d Mon Sep 17 00:00:00 2001 From: Marty Oehme Date: Sun, 8 Jan 2023 17:27:17 +0100 Subject: [PATCH 3/5] Remove strict nsxiv references in usage information --- uoeia | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/uoeia b/uoeia index 0784013..6672c60 100755 --- a/uoeia +++ b/uoeia @@ -11,21 +11,21 @@ Can open remote urls of individual images, galleries, as well as local files at Uses gallery-dl for remote gallery opening - so if gallery-dl can open it, so can your image viewer. Options: - -v, --viewer Specify the image viewer to use (default: nsxiv). + -v, --viewer Specify the image viewer to use. -q, --quiet Don't display any output during normal operation. -g, --gdlopts Pass through options to gallery-dl. Take care to fully quote each passed option. -r, --replace Url patterns to replace in the format 'mypattern:::myreplacement' -h, --help Show this help message and exit. Examples: - uoeia my-image.jpg Display a local image file using nsxiv. + uoeia my-image.jpg Display a local image file. - uoeia https://example.com/image Display an image/image gallery from a URL using nsxiv. + uoeia https://example.com/image Display an image/image gallery from a URL. uoeia -v imv https://example.com/image Display an image from a URL using imv. uoeia -g \"--range 1-10\" https://reddit.com/r/earthporn - Download and display the first 10 results using nsxiv. + Download and display the first 10 results. uoeia -r 'nitter.net:::twitter.com' https://nitter.net/donttrythis/ Display images from twitter directly instead of its From 5a6c826ca572a6b603aa988e421493086ec48737 Mon Sep 17 00:00:00 2001 From: Marty Oehme Date: Sun, 8 Jan 2023 17:27:39 +0100 Subject: [PATCH 4/5] Refactor default image viewer finding --- uoeia | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/uoeia b/uoeia index 6672c60..7619987 100755 --- a/uoeia +++ b/uoeia @@ -86,17 +86,10 @@ dereference() { } 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 + for cmd in nsxiv sxiv feh imv vimiv; do + if command -v "$cmd" 1>/dev/null 2>&1; then program="$cmd"; break; fi + done + echo "$program" } main() { From 1ceacc5b22bbda4126bd357d56b9c71778b932c8 Mon Sep 17 00:00:00 2001 From: Marty Oehme Date: Sun, 8 Jan 2023 17:27:53 +0100 Subject: [PATCH 5/5] Add error message if no suitable image viewer found --- uoeia | 1 + 1 file changed, 1 insertion(+) diff --git a/uoeia b/uoeia index 7619987..7e202c9 100755 --- a/uoeia +++ b/uoeia @@ -93,6 +93,7 @@ get_imageviewer() { } main() { + [ -n "$imageviewer" ] || die "Error: Could not find a suitable image viewer, set one manually with the '-v' option." command -v "${imageviewer}" 1>/dev/null 2>&1 || die "Error: Opening images in ${imageviewer} requires ${imageviewer} to be installed and and on the path." trap cleanup EXIT