aboutsummaryrefslogtreecommitdiff
path: root/sys/code
diff options
context:
space:
mode:
authorxero <x@xero.nu>2014-08-05 13:08:34 -0400
committerxero <x@xero.nu>2014-08-05 13:08:34 -0400
commit74e553965db2cbc769566837eefa13739f31f926 (patch)
treef85601d8305ae3bb5fd8890bcc27bb6a97704606 /sys/code
parentb3d58930a8bfd34c89455284ecd3536696914850 (diff)
downloaddotfiles_ascii-74e553965db2cbc769566837eefa13739f31f926.tar.xz
dotfiles_ascii-74e553965db2cbc769566837eefa13739f31f926.zip
add terminal image viewer (thanx z3bra!) and added zsh alias for it.
Diffstat (limited to '')
-rw-r--r--sys/code/sys/img32
1 files changed, 32 insertions, 0 deletions
diff --git a/sys/code/sys/img b/sys/code/sys/img
new file mode 100644
index 0000000..ba58ac0
--- /dev/null
+++ b/sys/code/sys/img
@@ -0,0 +1,32 @@
+#!/bin/bash
+#
+# z3bra -- 2014-01-21
+# requires `w3m` package
+
+test -z "$1" && exit
+
+W3MIMGDISPLAY="/usr/lib/w3m/w3mimgdisplay"
+FILENAME=$1
+FONTH=14 # Size of one terminal row
+FONTW=8 # Size of one terminal column
+COLUMNS=`tput cols`
+LINES=`tput lines`
+
+read width height <<< `echo -e "5;$FILENAME" | $W3MIMGDISPLAY`
+
+max_width=$(($FONTW * $COLUMNS))
+max_height=$(($FONTH * $(($LINES - 2)))) # substract one line for prompt
+
+if test $width -gt $max_width; then
+height=$(($height * $max_width / $width))
+width=$max_width
+fi
+if test $height -gt $max_height; then
+width=$(($width * $max_height / $height))
+height=$max_height
+fi
+
+w3m_command="0;1;0;0;$width;$height;;;;;$FILENAME\n4;\n3;"
+
+tput cup $(($height/$FONTH)) 0
+echo -e $w3m_command|$W3MIMGDISPLAY \ No newline at end of file