Last active
August 29, 2015 14:09
-
-
Save Eltiech/7767709a81ec6088ac49 to your computer and use it in GitHub Desktop.
fireview
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
#Author: Malsententia <[email protected]> | |
#Purpose: Uses a chromeless firefox window as an image viewer. | |
# Inferior to most other image viewers, but good for APNGs | |
# Opens kinda fast if you already have firefox running, I guess? | |
#Usage: fireview image.ext | |
#Requires: file - gets the resolution | |
# firefox - duh | |
# xrandr - determines monitor resolution for max window size | |
# xdotool - figures out which monitor your mouse is on, for above | |
# grep,sed - also duh | |
#License: WTFPL | |
#Notes: I should probably break my habit of using all caps vars in my bash | |
OLDIFS="$IFS" | |
IFS="x+"$'\n' | |
MONITORS=($(xrandr | grep " connected" | grep -Poh '\d{3,}x\d{3,}\+\d+\+\d+')) | |
DIMS=($(file "$1"| grep -Poh ' \d+ x \d+(?=,)' | sed 's/ //g')) | |
MCOUNT="$((${#MONITORS[@]}/4))" | |
POS=($(xdotool getmouselocation --shell 2>/dev/null | grep -Poh "(?<=(X|Y)=)\d+")) | |
IFS="$OLDIFS" | |
POSX=${POS[0]} | |
POSY=${POS[1]} | |
IMGW=${DIMS[0]} | |
IMGH=${DIMS[1]} | |
for ((i=0;i<MCOUNT;i++)); do | |
o=$((i*4)) | |
XMIN=$((MONITORS[2+$o])) | |
XMAX=$((MONITORS[2+$o]+MONITORS[$o])) | |
YMIN=$((MONITORS[3+$o])) | |
YMAX=$((MONITORS[3+$o]+MONITORS[1+$o])) | |
if ((POSY>=YMIN && POSY<YMAX && POSX>=XMIN && POSX<XMAX)); then | |
XMON=$((MONITORS[$o])) | |
YMON=$((MONITORS[1+$o])) | |
break | |
fi | |
done | |
WIDTH=$((XMON-40)) | |
HEIGHT=$((YMON-40)) | |
if ((IMGW<64));then | |
WIDTH=64 | |
elif ((IMGW<WIDTH));then | |
WIDTH=$IMGW | |
fi | |
if ((IMGH<40));then | |
HEIGHT=40 | |
elif ((IMGH<HEIGHT));then | |
HEIGHT=$IMGH | |
fi | |
cat << FFVIEWHDOC > /dev/shm/ffvtemp | |
<html><head><meta http-equiv="refresh" content="0;URL=file://$(realpath $1)"></head><body bgcolor="#000" style="width:$WIDTH; height:$HEIGHT"></body></html> | |
FFVIEWHDOC | |
firefox -chrome "file:///dev/shm/ffvtemp" &>/dev/null |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment