scripts

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

commit 13474a954659932ba0cacf0c3e74625fea0eaad4
parent 3d570a262b644b9aa53c2b113bc3b9a181fd76d6
Author: z3bra <willy@mailoo.org>
Date:   Thu Oct 23 16:50:41 +0200

Merge branch 'master' of z3bra.org:scripts

Diffstat:
bak | 88+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
instagram | 13+++++--------
menu | 5+++--
popup | 2+-
prtmk | 6++++++
prtup | 9++++++++-
regmv | 18++++++++++++++++++
setwall | 18++++++++++++++++++
8 files changed, 147 insertions(+), 12 deletions(-)
diff --git a/bak b/bak @@ -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 diff --git a/instagram b/instagram @@ -9,7 +9,6 @@ VIEWER=meh EXEC_UPLOAD=~/bin/imgurup -SSHOT_DIR=$PWD WMNAME=`xprop -root WM_NAME|cut -d\" -f2` upload() { @@ -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 } @@ -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`;; @@ -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} diff --git a/menu b/menu @@ -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 diff --git a/popup b/popup @@ -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}'` diff --git a/prtmk b/prtmk @@ -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 @@ -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 diff --git a/prtup b/prtup @@ -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) @@ -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 @@ -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 diff --git a/regmv b/regmv @@ -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 diff --git a/setwall b/setwall @@ -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