scripts

various script and utils
git clone git://z3bra.org/scripts
Log | Files | Refs

commit afab40cb5d4919f76070438bdaa8bd1f153359f2
parent bc785d69826def5c3cc00f91974a4464019f9bcd
Author: Willy Goiffon <willy@mailoo.org>
Date:   Fri Jan  3 10:41:07 +0100

Fixed options and made the script posix compliant (i guess)

Diffstat:
instagram | 79+++++++++++++++++++++++++++++++++++++++++++------------------------------------
1 file changed, 43 insertions(+), 36 deletions(-)
diff --git a/instagram b/instagram @@ -1,30 +1,31 @@ -#!/bin/bash -# -# 2013 Willy 'z3bra' Goiffon <willy at mailoo dot org> +#!/bin/sh # +# 2013 z3bra <willy at mailoo dot org> # INSTAGRAM - screenshot taker / manager # # Licensed under WTFPL 2.0 -# # >> http://www.wtfpl.net/txt/copying/ # IMAGE_DIR=~/usr/img EXEC_UPLOAD=~/bin/upload SSHOT_DIR=${IMAGE_DIR}/wm +WMNAME=`xprop -root WM_NAME|cut -d\" -f2` + +function upload() { + $EXEC_UPLOAD $1 +} -source ~/.config/instagram 2>/dev/null function usage() { cat <<SHBLAH Usage : instagram [-tmuwh] [-g number] [-s screen] [filename.png] -t : create thumbnail - -m : create one shot per head -u : upload the file using $UPLOAD_BIN <filename> -w : take only a window for the shot (choose with pointer) -h : display this help -d path : save the shot in <path> - -g : create a gif (press ctrl-C to stop) + -g : create a gif (press 'q' to stop) -s screen : use only the screen number <screen> for the shot Also, do not give path to shot. They're saved to $SSHOT_DIR by default. @@ -43,20 +44,36 @@ function upload() { $EXEC_UPLOAD $1 } -[[ "$1" = "--help" ]] && usage && exit 0 +function headshot() { + + xdpyinfo -ext XINERAMA | sed 's/^ head #//p' | + while IFS=' :x@,' read i w h x y; do + if [[ $1 = "$i" ]]; then + import -window $WINDOW -crop ${w}x${h}+${x}+${y} $SSHOT_DIR/$OUTPUT + fi + done +} + +function gifit() { + + test -z "$SCREEN" && SCREEN=0 + RES=`xdpyinfo -ext XINERAMA | sed -n "s/^ head #$SCREEN: \([0-9x]*\) .*$/\1/p"` + + mkdir $SSHOT_DIR/tmp + ffmpeg -f x11grab -s $RES -r 12 -i :0.$SCREEN $SSHOT_DIR/tmp/$1 -# default window id -WINDOW='root' +} + +[[ "$1" = "--help" ]] && usage && exit 0 while getopts ":htmuwd:gs:" opt; do case $opt in t) THUMB=1 ;; - m) MULTI=1 ;; d) SSHOT_DIR=$OPTARG ;; g) GIF=1 ;; s) SCREEN=$OPTARG ;; u) UPLOAD=1 ;; - w) WINDOW=$(xprop|grep 'window id'|cut -d\ -f7);; + w) WINDOW=`xprop|grep 'window id'|cut -d\ -f7`;; h) usage; exit 0;; ?) echo "invalid option: -$OPTARG"; exit 1 ;; esac @@ -64,36 +81,26 @@ done shift $((OPTIND-1)) -if [[ -z "$1" ]]; then - OUTPUT="$USER-$(date +%Y-%m-%d).png" -else - OUTPUT=$1 -fi - -if [[ "$MULTI" = "1" ]] || [[ -n $SCREEN ]]; then - xdpyinfo -ext XINERAMA | sed '/^ head #/!d;s///' | - while IFS=' :x@,' read i w h x y; do - if [[ $SCREEN = "$i" ]] || [[ -z $SCREEN ]]; then - import -window ${WINDOW} -crop ${w}x$h+$x+$y $SSHOT_DIR/head_$i-$OUTPUT - [[ -n $THUMB ]] && import -window ${WINDOW} -thumbnail 25% -crop ${w}x$h+$x+$y $SSHOT_DIR/thumb-head_$i-$OUTPUT - fi - done +test -z $1 && OUTPUT=$WMNAME-`date +%Y-%m-%d`.png || OUTPUT=$1 +test -z "$WINDOW" && WINDOW='root' -elif [ -n "$GIF" ]; then - mkdir $SSHOT_DIR/tmp - ffmpeg -f x11grab -s 1440x900 -r 25 -i :0.0 $SSHOT_DIR/tmp/out.mov - ffmpeg -i $SSHOT_DIR/tmp/out.mov -r 1 -f image2 $SSHOT_DIR/tmp/%05d.jpg - convert -delay 100 $SSHOT_DIR/tmp/*.jpg $SSHOT_DIR/${OUTPUT} - rm -rf $SSHOT_DIR/tmp +if [ -n "$GIF" ]; then + OUTPUT=${OUTPUT/.png/.gif} + gifit $OUTPUT +elif [ -n "$SCREEN" ]; then + OUTPUT=head_$SCREEN-$OUTPUT + headshot $SCREEN else import -window ${WINDOW} $SSHOT_DIR/$OUTPUT - [[ -n $THUMB ]] && import -window ${WINDOW} -thumbnail 25% $SSHOT_DIR/thumb-${OUTPUT} fi -if [[ "$UPLOAD" = "1" ]]; then +test -n "$THUMB" && import -window ${WINDOW} -thumbnail 25% $SSHOT_DIR/thumb-${OUTPUT} + + +meh $SSHOT_DIR/$OUTPUT + +if [ "$UPLOAD" = "1" ]; then cd ${IMAGE_DIR} upload wm/${OUTPUT} fi - -meh $SSHOT_DIR/$OUTPUT