SHARE
TWEET

xereeto's terminal image viewer

a guest Nov 13th, 2012 112 Never
  1. #!/bin/bash
  2. # this will be important later:
  3. imgvwr="$(locate w3m-img)"
  4. if [ -z "$1" ]; then
  5.         echo "must specify a filename."
  6.         exit 1
  7. elif [ -z "$(which w3m)" ]; then
  8.         echo "Error: w3m must be installed."
  9.         exit 1
  10. elif  [ "$(expr index '$imgvwr' '/usr/share/doc/w3m-img')" == "0" ]; then
  11.         # remember the imgvwr from before?
  12.         echo "Error: w3m-img must be installed."
  13.         exit 1
  14. fi
  15. S1="$1"
  16. # if a relative path has been given,
  17. # add the currrent directory to it
  18. if [ ! "${1:0:1}" == "/" ]; then
  19.         S1="$(pwd)/$1"
  20. fi
  21. # for aesthetics only, so we
  22. # can display the filename
  23. S2="$(basename $S1)"
  24. # creates the temporary HTML document so we can view the image
  25. echo "<html><head><title>$S2</title></head><body>&nbsp;<img src='$S1' alt='$S2'><br>&nbsp;</body></html>" > /tmp/xerimgvwr.$$.html
  26. w3m /tmp/xerimgvwr.$$.html
  27. # tidy up time
  28. rm /tmp/xerimgvwr.$$.html
RAW Paste Data
Top