nsxivurl 562 B

123456789101112131415161718192021222324252627282930313233
  1. #!/bin/sh
  2. cache_dir="${TMPDIR:-/tmp}/nsxiv"
  3. die() {
  4. [ -n "$1" ] && printf '%s\n' "$*" >&2;
  5. exit 1
  6. }
  7. cleanup() {
  8. rm -f -- "$cache_dir"/*
  9. }
  10. get_image() (
  11. cd "$cache_dir" && curl -sSLO "$1"
  12. )
  13. ### main ###
  14. [ -z "$1" ] && die "No arguments given"
  15. trap cleanup EXIT
  16. [ -d "$cache_dir" ] || mkdir -p -- "$cache_dir" || die
  17. while [ -n "$1" ]; do
  18. case "$1" in
  19. *://*.*) get_image "$1" ;;
  20. *) echo "Invalid url: $1" >&2 ;;
  21. esac
  22. shift
  23. done
  24. [ "$(find "$cache_dir" -type f -print | wc -l)" -ne 0 ] &&
  25. nsxiv -p "$cache_dir"