tmore cool scripts - scripts - various script and utils
 (HTM) git clone git://z3bra.org/scripts
 (DIR) Log
 (DIR) Files
 (DIR) Refs
       ---
 (DIR) commit a5234b88fbe76e3fe0f45a081fba4e59dc2c792c
 (DIR) parent 7224b18f9d6f82004db53d5964daa4baa7e627f2
 (HTM) Author: z3bra <willy@mailoo.org>
       Date:   Mon, 30 Mar 2015 22:57:15 +0200
       
       more cool scripts
       
       Diffstat:
         D chan                                |      54 -------------------------------
         A download                            |       4 ++++
         A fadevid                             |      28 ++++++++++++++++++++++++++++
         A grid                                |      91 +++++++++++++++++++++++++++++++
         A irc-chat                            |      14 ++++++++++++++
         A irc-connect                         |      30 ++++++++++++++++++++++++++++++
         A love                                |       3 +++
         A notii                               |      36 +++++++++++++++++++++++++++++++
         A pass                                |      50 +++++++++++++++++++++++++++++++
       
       9 files changed, 256 insertions(+), 54 deletions(-)
       ---
 (DIR) diff --git a/chan b/chan
       t@@ -1,54 +0,0 @@
       -#!/bin/sh
       -
       -## ii directory
       -ROOT=~/var/irc
       -
       -# irc parameters
       -NICK='ptii'
       -SERV='irc.freenode.net'
       -PORT='6667'
       -CHAN='z3bra'
       -
       -usage() {
       -    cat << EOF
       -    usage: chat [-h] [-s server] [-c channel] [-n nickname]
       -EOF
       -}
       -
       -test -n "$1" && CHAN=$1
       -test -n "$2" && NICK=$2
       -
       -while getopts ":hn:c:s:" opt; do
       -    case $opt in
       -        h) usage; exit 0;;
       -        n) NICK=$OPTARG;;
       -        s) SERV=$OPTARG;;
       -        c) CHAN=$OPTARG;;
       -        ?) echo "Invalid option -$OPTARG"; exit 1;;
       -        *) usage; exit 1;;
       -    esac
       -done
       -
       -# commands launched on startup
       -JOIN="/j $CHAN hai $CHAN!"
       -
       -# spawn ii
       -ii -i $ROOT -n $NICK -s $SERV -p $PORT &
       -
       -while [ ! -p $ROOT/$SERV/in ]; do
       -    echo awaiting connection to $SERV...;
       -    sleep 2;
       -done
       -
       -# launch commands at start
       -echo "$JOIN" > $ROOT/$SERV/in
       -
       -while [ ! -p $ROOT/$SERV/$CHAN/in ]; do
       -    echo Starting chatting with $CHAN;
       -    sleep 1;
       -done
       -
       -cd $ROOT/$SERV/$CHAN
       -tmux new-session -d -s irc 'tail -f out' \; split-window -l 1 'ptii' \; attach
       -
       -rm -rf $ROOT/$SERV
 (DIR) diff --git a/download b/download
       t@@ -0,0 +1,4 @@
       +#!/bin/sh
       +
       +OUT="$(thinglaunch -o)"
       +curl -s "$@" > $OUT
 (DIR) diff --git a/fadevid b/fadevid
       t@@ -0,0 +1,28 @@
       +#!/bin/sh
       +
       +# fuck you, ffmpeg banner
       +exec 2>/dev/null
       +
       +OUTDIR=$PWD/faded
       +FADELEN=30
       +FONTPARAM="fontfile=$HOME/tmp/bitmicro.ttf:shadowx=4:shadowy=4:fontcolor=white:fontsize=28:x=w-tw-28:y=h-th-28"
       +
       +getname() {
       +    echo $1 | sed 's/\(.*\)\.[^.]*/\L\1/'
       +}
       +
       +getframes() {
       +    ffprobe -count_frames -show_entries stream=nb_read_frames $IN|cut -sd= -f2
       +}
       +
       +test ! -d $OUTDIR && mkdir -p $OUTDIR
       +
       +for IN in $@; do
       +    printf "%s ... " "$(getname $IN)"
       +    NBFRAME=$(getframes)
       +    VFILTER="fade=in:0:$FADELEN"
       +    VFILTER="$VFILTER,fade=out:$((NBFRAME - FADELEN)):$FADELEN"
       +    VFILTER="$VFILTER,drawtext=$FONTPARAM:text=$(getname $IN)"
       +    ffmpeg -i $IN -vf "$VFILTER" -b:v 5M -y $OUTDIR/$IN
       +    printf "OK\n"
       +done
 (DIR) diff --git a/grid b/grid
       t@@ -0,0 +1,91 @@
       +#!/bin/sh
       +#
       +# Copyright (c) 2015 Greduan <me@greduan.com>, licensed under the WTFPL license
       +#
       +# When used puts all the windows in a grid and when you focus one of the windows
       +# it puts all the windows back to their original location and focuses the window
       +# you switched to.
       +# depends on: wew focus.sh
       +
       +GAP=${GAP:-20}
       +ROOT=$(lsw -r)
       +SW=$(wattr w $ROOT)
       +SH=$(wattr h $ROOT)
       +SH=$(wattr h $ROOT)
       +PFW=$(pfw)
       +TEMP=$(mktemp) && wattr xywhi $(lsw) > $TEMP
       +BW=2
       +
       +# reduce the screen area at first, so we won't have to do it later... It will
       +# greatly improve expressions, trust me!
       +SW=$(( SW - GAP - 2*BW ))
       +SH=$(( SH - GAP - 2*BW ))
       +
       +# figure out the dimensions of the windows and locations
       +NB=$(wc -l < $TEMP)
       +
       +# calculate the size of the grid using the square root of the number of windows
       +ROWS=$(echo "sqrt($NB)" | bc)
       +COLS=$ROWS
       +
       +# for each row...
       +for r in `seq 1 $ROWS`; do
       +
       +    # .. if we're on the last row, display all the remaining windows
       +    # eg: if we have 12 windows, the square root would be 3 (truncated).
       +    # so the script would draw a 3x3 grid. This would leave 3 windows apart. To
       +    # avoid this, we set the number of columns of the last row as
       +    #
       +    #    12 - 3 * (3-1)
       +    # => 12 - 3 * 2
       +    # => 12 - 6
       +    # == 6
       +    # so we will have 6 windows on the last row, instead of 3.
       +    # This do not lead to the best looking grid, I know (the best one would be
       +    # 3x4), but it's the simplest algo I've found. Don't forget we're playing
       +    # with shell scripts here, not matlab..
       +    test $r -eq $ROWS && COLS=$(( NB - ROWS * (ROWS-1) ))
       +
       +    # for each column of each row..
       +    for c in `seq 1 $COLS`; do
       +
       +        # exit if we don't have other windows to display
       +        test $(( (r-1)*r + c )) -gt $NB && break
       +
       +        # heigh of windows (total heigh minus gaps and borders)
       +        H=$(( SH/ROWS - GAP - BW ))
       +        # same for width
       +        W=$(( SW/COLS - GAP - BW ))
       +
       +        # and the tricky part..
       +        # The X offset is the width * the actual column (starting from 0) + the
       +        # gaps/borders multiplied by the column number (draw it on a sheet of
       +        # paper like me, it will make much more sense!
       +        X=$(( W * (c-1) + c*(GAP + BW) ))
       +        # same for the Y offset
       +        Y=$(( H * (r-1) + r*(GAP + BW) ))
       +
       +        # finally, teleport the window to the place we just calculated.
       +        # the sed trick is used to get the corresponding line number in the file
       +        # holding the window infos.
       +        wtp $X $Y $W $H $(sed "$(( (r-1)*r + c ))p;d" $TEMP | cut -d\  -f5)
       +    done
       +done
       +
       +# loop through wew to hear for when you focus a new window
       +wew | while IFS=: read ev wid; do
       +    case $ev in
       +        4)
       +            while read line; do
       +                wtp $line
       +            done < $TEMP
       +            vroum $wid
       +            exit
       +            ;;
       +    esac
       +    # TODO: add a thing so that if the same window is clicked it puts windows
       +    #       back and focuses the same window
       +done
       +
       +# cleanup
       +rm $TEMP
 (DIR) diff --git a/irc-chat b/irc-chat
       t@@ -0,0 +1,14 @@
       +#!/bin/sh
       +
       +usage() {
       +    echo "usage: $(basename $0) [-h] [-s server]" >&2
       +    exit 1
       +}
       +
       +test -z "$1" && usage
       +
       +CHANNEL="$1"
       +echo "/j $CHANNEL" > in
       +cd "$CHANNEL"
       +
       +tail -n28 out | hiii
 (DIR) diff --git a/irc-connect b/irc-connect
       t@@ -0,0 +1,30 @@
       +#!/bin/sh
       +
       +## ii directory
       +BASEDIR=~/var/irc
       +
       +# irc parameters
       +NICKNAME='z3bra'
       +PASSWORD='password'
       +SERVERS=${1:-'irc.nixers.net irc.rizon.net irc.oftc.net irc.freenode.net'}
       +PORT='6667'
       +
       +usage() {
       +    echo "usage: $(basename $0) [-h] [-s server]" >&2
       +    exit 1
       +}
       +
       +while getopts ":hn:s:" opt; do
       +    case $opt in
       +        h) usage; exit 0;;
       +        n) NICK=$OPTARG;;
       +        s) SERV=$OPTARG;;
       +        ?) echo "Invalid option -$OPTARG"; exit 1;;
       +        *) usage;;
       +    esac
       +done
       +
       +# spawn ii
       +for SERVER in $SERVERS; {
       +    ii -i $BASEDIR -n $NICKNAME -s $SERVER -p $PORT -k $PASSWORD &
       +}
 (DIR) diff --git a/love b/love
       t@@ -0,0 +1,3 @@
       +#!/bin/sh
       +
       +printf "%s\n" "♥"
 (DIR) diff --git a/notii b/notii
       t@@ -0,0 +1,36 @@
       +#!/bin/sh
       +
       +NICK=z3bra
       +FONT="-*-creep-*-*-*--16-*-*-*-*-*-*-1"
       +GEOM=180x20+1250+10
       +
       +untimestamp() {
       +    sed 's/^[-: 0-9]*//'
       +}
       +
       +catchnick() {
       +    grep -v "<$NICK>" | grep "$NICK"
       +}
       +
       +cutmask() {
       +    cut -f2
       +}
       +
       +limitio() {
       +    xargs tail -n1
       +}
       +
       +scroll() {
       +    skroll -r -n28 -d0.1
       +}
       +
       +barify() {
       +    ifne lemonbar -d -B\#161616 -f $FONT -g $GEOM
       +}
       +
       +OUTFILE=
       +for f in $@; {
       +    OUTFILE="$OUTFILE -f $f"
       +}
       +
       +wendy -v -m 8 $OUTFILE | cutmask #| xargs tail -n1 | catchnick | untimestamp | scroll | barify
 (DIR) diff --git a/pass b/pass
       t@@ -0,0 +1,50 @@
       +#!/bin/sh
       +# z3bra - 2015 (c) wtfpl
       +# simple password manager
       +# depends on: gpg2
       +
       +FILE=${FILE:-~/.pass}
       +GPGID=willy
       +
       +usage() {
       +    echo "usage: $(basename $0) [-ad <name>]" >&2
       +    exit 1
       +}
       +
       +encrypt() {
       +    gpg2 -e -r $GPGID | sponge $FILE
       +}
       +
       +decrypt() {
       +    gpg2 -d --batch --quiet -u $GPGID $FILE 
       +}
       +
       +pass_lst() {
       +    decrypt | cut -d: -f1
       +}
       +
       +pass_add() {
       +    printf "password for '$1':"; read -s PASS; echo
       +    printf "do it again! '$1':"; read -s PASS2; echo
       +    test "$PASS" != "$PASS2" && echo "nope, sorry." && exit 1
       +    decrypt | (cat; echo "${1}:${PASS}") | encrypt
       +}
       +
       +pass_get() {
       +    decrypt | grep -E "^${1}:" | cut -d: -f2-
       +}
       +
       +pass_del() {
       +    decrypt | grep -vE "^${1}:" | encrypt
       +}
       +
       +test -f $FILE || encrypt < /dev/null
       +# only list password names and exit
       +test $# -lt 1 && pass_lst && exit 0
       +
       +case $1 in
       +    -h) usage ;;
       +    -a) pass_add "$2" ;;
       +    -d) pass_del "$2" ;;
       +    *)  pass_get "$@" ;;
       +esac