diff --git a/uoeia b/uoeia index 0e179f6..7e202c9 100755 --- a/uoeia +++ b/uoeia @@ -5,27 +5,27 @@ 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. 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 @@ -33,9 +33,6 @@ Examples: " } -cache_dir="$(mktemp -d)" -imageviewer=nsxiv - die() { [ -n "$1" ] && printf '%s\n' "$*" >&2 exit 1 @@ -88,11 +85,19 @@ dereference() { echo "$output" } +get_imageviewer() { + 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() { - command -v "${imageviewer}" 1>/dev/null 2>&1 || die "Opening images in ${imageviewer} requires ${imageviewer} to be installed and and on the path." + [ -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 - [ -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 @@ -107,8 +112,11 @@ main() { ${imageviewer} "$cache_dir" } +cache_dir="$(mktemp -d)" +imageviewer="$(get_imageviewer)" gal_args=() replacements=() + while [[ $# -gt 0 ]]; do case "$1" in -h | --help)