Last active
December 15, 2015 12:49
Revisions
-
tomoe-mami revised this gist
Mar 30, 2013 . 1 changed file with 12 additions and 8 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -2,19 +2,21 @@ WIDTH=10 HEIGHT=4 LABEL="yes" # show filename under thumbnail VIDEO="no" # don't show video thumbnail. only show generic icon CHAR="." if [ ! "$TERMINOLOGY" = "1" ]; then echo "This script only works in Terminology" >&2 exit 1 fi while getopts ":w:h:nv" opt; do case "$opt" in w) WIDTH="$OPTARG" ;; h) HEIGHT="$OPTARG" ;; n) LABEL="no" ;; v) VIDEO="yes" ;; :) echo "Option -$OPTARG requires a value" >&2 exit 1 @@ -84,14 +86,16 @@ function get_thumb { # there are still more file formats supported by terminology. # these are just few i used most case "$EXT" in jpg|jpeg|png|gif|bmp|ico|xcf|svg|pdf) THUMB="$1";; avi|mp4|mkv|asf|wmv|ogv|mpg|rmvb|flv) if [ "$VIDEO" = "yes" ]; then THUMB="$1" else THUMB="video-x-generic" fi ;; mp3|aac|flac|ogg|wma|wav|ape) THUMB="audio-x-generic" ;; -
tomoe-mami revised this gist
Mar 30, 2013 . 1 changed file with 93 additions and 34 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,9 +1,37 @@ #!/bin/sh WIDTH=10 HEIGHT=4 LABEL="yes" CHAR="." if [ ! "$TERMINOLOGY" = "1" ]; then echo "This script only works in Terminology" >&2 exit 1 fi while getopts ":w:h:n" opt; do case "$opt" in w) WIDTH="$OPTARG" ;; h) HEIGHT="$OPTARG" ;; n) LABEL="no" ;; :) echo "Option -$OPTARG requires a value" >&2 exit 1 ;; esac done shift $((OPTIND - 1)) if [ $WIDTH -lt 1 ]; then WIDTH=10 fi if [ $HEIGHT -lt 1 ]; then HEIGHT=4 fi if [ -z "$*" ]; then PARAM="./*" else @@ -34,63 +62,94 @@ function declare_inline_media { echo -ne "\e}it$CHAR$WIDTH;$HEIGHT;$1\0" } # $1 = direction (left/right/up/down) # $2 = amount function move { local OP case "$1" in left) OP="D" ;; right) OP="C" ;; up) OP="A" ;; down) OP="B" ;; esac echo -ne "\e[${2:-1}$OP" } # $1 = absolute path function get_thumb { if [ -d "$1" ]; then THUMB="folder" else EXT="${1##*.}" # there are still more file formats supported by terminology. # these are just few i used most case "$EXT" in jpg|jpeg|png|gif|svg|pdf) THUMB="$ABSPATH";; avi|mp4|mkv|asf|wmv|ogv|mpg|rmvb|flv) THUMB="video-x-generic" ;; swf) THUMB="application-x-shockwave-flash" ;; mp3|aac|flac|ogg|wma|wav|ape) THUMB="audio-x-generic" ;; zip|rar|ace|gz|bz2|tbz2|tgz|cbz|cbr|7z|xz) THUMB="application-x-archive" ;; txt|srt|edc|c|h|sh|py|rb|lua|go|php|cpp|h|hpp|cc|hh|md|vim|conf|ini|am|ac|in|xml|html|xhtml|rss|atom|README|TODO|NOTES|ChangeLog|NEWS|AUTHORS|COPYING|INSTALL) THUMB="text-x-generic" ;; *) THUMB="empty";; esac fi } get_info COL=1 for FILENAME in $PARAM; do ABSPATH="$(realpath "$FILENAME")" BASENAME="$(basename "$ABSPATH")" get_thumb "$ABSPATH" declare_inline_media "$THUMB" for (( ROW = 0 ; ROW < $HEIGHT ; ROW++ )); do print_block move left $WIDTH move down done if [ "$LABEL" = "yes" ]; then CAPTION="${BASENAME:0:$WIDTH}" LEFT_PAD=$(( ($WIDTH + ${#CAPTION}) / 2 )) printf "%*s" $LEFT_PAD "$CAPTION" move left $LEFT_PAD fi COL=$(( $COL + $WIDTH + 3 )); if [ $COL -ge $TERM_WIDTH ]; then COL=1 if [ "$LABEL" = "yes" ]; then echo fi echo else move right $(( $WIDTH + 2 )) move up $HEIGHT fi done if [ $COL -gt $WIDTH -a $COL -lt $TERM_WIDTH ]; then move down $HEIGHT if [ "$LABEL" = "yes" ]; then echo fi fi echo -
tomoe-mami created this gist
Mar 28, 2013 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,96 @@ #!/bin/sh WIDTH=6 HEIGHT=3 CHAR="." if [ -z "$*" ]; then PARAM="./*" else PARAM=$* fi function get_info { local ORIG_STTY="$(stty -g)" stty -echo echo -ne "\e}qs\0" read RESPONSE stty "$ORIG_STTY" TERM_WIDTH="$(echo "$RESPONSE" | cut -d';' -f1)" TERM_HEIGHT="$(echo "$RESPONSE" | cut -d';' -f2)" } function print_block { echo -ne "\e}ib\0" for (( c = 0 ; c < $WIDTH ; c++ )); do echo -n "$CHAR" done echo -ne "\e}ie\0" } # $1 = path function declare_inline_media { echo -ne "\e}it$CHAR$WIDTH;$HEIGHT;$1\0" } # $1 = amount function move_left { echo -ne "\e[${1}D" } # $1 = amount function move_right { echo -ne "\e[${1}C" } # $1 = amount function move_up { echo -ne "\e[${1}A" } # $1 = amount function move_down { echo -ne "\e[${1}B" } get_info COL=1 for FILENAME in $PARAM; do ABSPATH="$(realpath "$FILENAME")" if [ -d "$ABSPATH" ]; then THUMB="folder" else BASENAME="$(basename "$ABSPATH")" EXT="${BASENAME##*.}" case "$EXT" in jpg|jpeg|png|gif|bmp|tif|ico|svg|pdf) THUMB="$ABSPATH";; *) THUMB="empty";; esac fi declare_inline_media "$THUMB" for (( ROW = 0 ; ROW < $HEIGHT ; ROW++ )); do print_block move_left $WIDTH move_down 1 done COL=$(( $COL + $WIDTH + 2 )); if [ $COL -ge $TERM_WIDTH ]; then COL=1 echo else move_right $(( $WIDTH + 1)) move_up $HEIGHT fi done for (( ROW = 0 ; ROW < $HEIGHT ; ROW++)); do echo; done