tMerge branch 'master' of z3bra.org:scripts - scripts - various script and utils
 (HTM) git clone git://z3bra.org/scripts
 (DIR) Log
 (DIR) Files
 (DIR) Refs
       ---
 (DIR) commit 13474a954659932ba0cacf0c3e74625fea0eaad4
 (DIR) parent 3d570a262b644b9aa53c2b113bc3b9a181fd76d6
 (HTM) Author: z3bra <willy@mailoo.org>
       Date:   Thu, 23 Oct 2014 16:50:41 +0200
       
       Merge branch 'master' of z3bra.org:scripts
       
       Diffstat:
         A bak                                 |      88 +++++++++++++++++++++++++++++++
         M instagram                           |      13 +++++--------
         M menu                                |       5 +++--
         M popup                               |       2 +-
         M prtmk                               |       6 ++++++
         M prtup                               |       9 ++++++++-
         A regmv                               |      18 ++++++++++++++++++
         A setwall                             |      18 ++++++++++++++++++
       
       8 files changed, 147 insertions(+), 12 deletions(-)
       ---
 (DIR) diff --git a/bak b/bak
       t@@ -0,0 +1,88 @@
       +#!/bin/sh
       +#
       +# z3bra - (c) wtfpl 2014
       +# Backup a file, and rotate backups : file.0.BAK - file.1.BAK, ...
       +#
       +# Based on a original idea from Ypnose. Thanks mate !
       +# <http://ypnose.org/blog/2014/bakup-snippet.html>
       +
       +EXT=${EXT:-BAK} # extension used for backup
       +LIM=${LIM:-9}   # maximum number of version to keep
       +PAD=${PAD:-0}   # number to start with
       +
       +usage() {
       +    cat <<EOF
       +usage: `basename $0` [-hrv] <file>
       +        -h          : print this help
       +        -r <num>    : perform <num> rotations if \$LIM is reached
       +EOF
       +}
       +
       +# report action performed in verbose mode
       +log() {
       +    # do not log anything if not in $VERBOSE mode
       +    test -z $VERBOSE && return
       +
       +    # add a timestamp to the message 
       +    echo "[$(date +%Y-%m-%d\ %H:%M)] - $*"
       +}
       +
       +# rotate backups to leave moar room
       +rotate() {
       +    # do not rotate if the rotate flags wasn't provided
       +    test -z $ROTATE && return
       +
       +    # delete the oldest backup
       +    rm ${FILE}.${PAD}.${EXT}
       +
       +    # move every file down one place
       +    for N1 in `seq $PAD $LIM`; do
       +        N2=$(( N1 + ROTATE ))
       +
       +        # don't go any further
       +        test -f ${FILE}.${N2}.${EXT} || return
       +
       +        # move file down $ROTATE place
       +        log "${FILE}.${N2}.${EXT} -> ${FILE}.${N1}.${EXT}"
       +        mv ${FILE}.${N2}.${EXT} ${FILE}.${N1}.${EXT}
       +    done
       +}
       +
       +# actually archive files
       +archive() {
       +    # test the presence of each version, and create one that doesn't exists
       +    for N in `seq $PAD $LIM`; do
       +        if test ! -f ${FILE}.${N}.${EXT}; then
       +
       +            # cope the file under it's new name
       +            log "Created: ${FILE}.${N}.${EXT}"
       +            cp ${FILE} ${FILE}.${N}.${EXT}
       +
       +            exit 0
       +        fi
       +    done
       +}
       +
       +while getopts "hrv" opt; do
       +    case $opt in
       +        h) usage; exit 0 ;;
       +        r) ROTATE=1 ;;
       +        v) VERBOSE=1 ;;
       +        *) usage; exit 1 ;;
       +    esac
       +done
       +
       +shift $((OPTIND - 1))
       +
       +test $# -lt 1 && usage && exit 1
       +
       +FILE=$1
       +
       +# in case limit is reach, remove the oldest backup
       +test -f ${FILE}.${LIM}.${EXT} && rotate
       +
       +# if rotation wasn't performed, we'll not archive anything
       +test -f ${FILE}.${LIM}.${EXT} || archive
       +
       +echo "Limit of $LIM .$EXT files reached run with -r to force rotation"
       +exit 1
 (DIR) diff --git a/instagram b/instagram
       t@@ -9,7 +9,6 @@
        
        VIEWER=meh
        EXEC_UPLOAD=~/bin/imgurup
       -SSHOT_DIR=$PWD
        WMNAME=`xprop -root WM_NAME|cut -d\" -f2`
        
        upload() {
       t@@ -33,7 +32,6 @@ Configuration:
            You can set variables here, so that they will overide the default ones:
        
            IMAGE_DIR   : Where images are stored
       -    SSHOT_DIR   : Where to save your shots
            EXEC_UPLOAD : Path to the script/program used to upload your shot
        SHBLAH
        }
       t@@ -43,17 +41,16 @@ 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
       +            import -window $WINDOW -crop ${w}x${h}+${x}+${y} $OUTPUT
                fi
            done
        }
        
        [[ "$1" = "--help" ]] && usage && exit 0
        
       -while getopts ":htmuwd:gs:" opt; do
       +while getopts ":htmuwgs:" opt; do
            case $opt in
                t) THUMB=1 ;;
       -        d) SSHOT_DIR=$OPTARG ;;
                s) SCREEN=$OPTARG ;;
                u) UPLOAD=1 ;;
                w) WINDOW=`xprop|grep 'window id'|cut -d\  -f7`;;
       t@@ -70,12 +67,12 @@ test -z "$WINDOW" && WINDOW='root'
        if [ -n "$SCREEN" ]; then
            headshot $SCREEN
        else
       -    import -window ${WINDOW} $SSHOT_DIR/$OUTPUT
       +    import -window ${WINDOW} $OUTPUT
        fi
        
       -test -n "$THUMB" && import -window ${WINDOW} -thumbnail 25% $SSHOT_DIR/thumb-${OUTPUT}
       +test -n "$THUMB" && import -window ${WINDOW} -thumbnail 25% thumb-$(basename ${OUTPUT})
        
        
       -$VIEWER $SSHOT_DIR/$OUTPUT
       +$VIEWER $OUTPUT
        
        test "$UPLOAD" = "1" && upload ${OUTPUT}
 (DIR) diff --git a/menu b/menu
       t@@ -12,6 +12,7 @@ X=`expr ${w} - 120 - 10`
        Y=`expr ${h} - 120 - 20`
        
        thingmenu -g 120x120 \
       -    "pop a terminal"    "urxvt" \
       -    "browse the web"    "dwb" \
       +    "play a game"       "steam" \
       +    "pop a term"        "urxvt" \
       +    "surf the web"      "dwb" \
            "restart 2bwm"      "pkill 2bwm; 2bwm" 2> /dev/null
 (DIR) diff --git a/popup b/popup
       t@@ -11,7 +11,7 @@ font='-*-stlarch-medium-r-*-*-10-*-*-*-*-*-*-*'
        font="$font,-*-gohufont-medium-*-*--11-*-*-*-*-*-iso10646-1"
        bg="#ff1d1d1d"
        fg="#ffffffff"
       -hl="#ff6ac0fd"
       +hl="#ff2288cc"
        
        IFS=' x' read x y <<< `xrandr | grep '*' | sed 1q | awk '{print $1}'`
        
 (DIR) diff --git a/prtmk b/prtmk
       t@@ -26,9 +26,14 @@ read -p 'Depends on : ' depends
        PORTDIR=$PORTDIR/$name
        
        if test "$version" = "git"; then
       +
            git_url=$sources
            sources=''
        
       +    read -p 'Git commit : ' sversion
       +
       +    version=git-$(echo $sversion | cut -c-7)
       +
            PKGFILE=${PKGFILE}-git
            PORTDIR=${PORTDIR}-git
        else
       t@@ -66,6 +71,7 @@ sed \
            -e "s__VERSION__$version" \
            -e "s__SOURCE__$sources" \
            -e "s__GIT_URL__$git_url" \
       +    -e "s__GIT_HASH__$sversion" \
            -i $PORTDIR/Pkgfile
        echo_color 2 OK
        
 (DIR) diff --git a/prtup b/prtup
       t@@ -28,6 +28,7 @@ get_version() {
        
            # enter the git directory
            if cd $name; then
       +        git pull origin master
        
                # get the git hash and its minimized version
                version=$(git log --oneline --format="git-%h" | sed 1q)
       t@@ -45,7 +46,7 @@ update_pkgfile() {
            sed -i "s/^version=.*$/version=$version/" Pkgfile
        
            # update sversion if it exists
       -    if grep 'sversion' Pkgfile; then
       +    if grep -q 'sversion' Pkgfile; then
                sed -i "s/^sversion=.*$/sversion=$sversion/" Pkgfile
        
            # create it otherwise
       t@@ -65,6 +66,12 @@ main() {
        
            # update Pkgfile accordingly
            update_pkgfile
       +
       +    if [ ! "$1" = "-q" ]; then
       +        echo "port   : $name"
       +        echo "version: $version"
       +        echo "commit : $sversion"
       +    fi
        }
        
        main
 (DIR) diff --git a/regmv b/regmv
       t@@ -0,0 +1,18 @@
       +#!/bin/sh
       +
       +test $# -ge 2 || { usage; exit 1; }
       +
       +test $1 = "-s" && simulate=1 && shift 1
       +
       +operation="$1"
       +
       +shift 1
       +
       +files="$*"
       +
       +for f in $files; do
       +    n=$(echo $f | sed "$operation")
       +    test -z "$simulate" && mv "$f" "$n" || echo "$f -> $n"
       +done
       +
       +exit 1
 (DIR) diff --git a/setwall b/setwall
       t@@ -0,0 +1,18 @@
       +#!/bin/sh
       +
       +bgdir="$HOME/usr/img/bg"
       +wall="$bgdir/default.jpg"
       +
       +test -z "$1" && return
       +
       +# get screen dir
       +IFS='x ' read sw sh <<< `xrandr | awk '/*/ {print $1}'`
       +
       +# get image dimensions (needs two lines because of IFS, no idea why)
       +IFS=' ' isize=`identify $1 | awk '{print $3}'`
       +IFS='x ' read iw ih <<< `echo $isize`
       +
       +test $iw -lt $sw && mode='tile' || mode='fill'
       +
       +test -L $1 && wall=$1 || ln -sf $1 $wall
       +hsetroot -${mode} $wall