dotfiles

*nix config files
git clone git://git.pyratebeard.net/dotfiles.git
Log | Files | Refs | README

webimg (942B)


      1 #!/bin/sh
      2 # ┓ ┳┳━┓┳━┓o┏┏┓┏━┓
      3 # ┃┃┃┣━ ┃━┃┃┃┃┃┃ ┳
      4 # ┗┻┇┻━┛┇━┛┇┛ ┇┇━┛
      5 #
      6 # requires `identify` from imagemagick
      7 
      8 img="/tmp/webimg"
      9 image=$(xsel -b)
     10 
     11 if [ -f ${img} ] ; then
     12 	rm -f ${img}
     13 fi
     14 
     15 function notify() {
     16 	msg=$1
     17 	notify-send -u 'normal' "webimg: ${msg}"
     18 }
     19 
     20 function show_img() {
     21 	if [[ ${image} = *w3mtmp* ]] ; then
     22 		img=${image}
     23 	elif [[ ${image} =~ .*gif$ ]] ; then
     24 		img="${img}.gif"
     25 		curl -s "${image}" --output ${img}
     26 	else
     27 		image="${image/http\:/https\:}"
     28 		image="${image/\/imgur/\/i\.imgur}"
     29 		curl -s "${image}" --output ${img}
     30 	fi
     31 
     32 	if identify ${img} 2>&1 1>/dev/null ; then
     33 		if identify ${img} | grep GIF 2>&1 1>/dev/null ; then
     34 			mv "${img}" $(echo "${img}".gif)
     35 			img="${img}.gif"
     36 		fi
     37 		sxiv -ba "${img}" 2>/dev/null
     38 	else
     39 		notify "not an image file"
     40 		exit 1
     41 	fi
     42 }
     43 
     44 [ $# -eq 1 ] && image="$1" ; show_img || show_img
     45 
     46 rm -f ${img}