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 44bde5d86fab450392b962f6ad1b8d952fbf5e1a
 (DIR) parent d0993fca06fad00026faaf81d1160dc6144476c2
 (HTM) Author: z3bra <willy@mailoo.org>
       Date:   Thu,  3 Apr 2014 23:37:35 +0200
       
       Merge branch 'master' of z3bra.org:scripts
       
       Conflicts:
               instagram
       
       Diffstat:
         A battery                             |      55 +++++++++++++++++++++++++++++++
         D battery.sh                          |      42 -------------------------------
         R dualhead.sh -> dualhead             |       0 
         R gamma.sh -> gamma                   |       0 
         M instagram                           |      45 ++++++-------------------------
         A mkbar                               |      94 +++++++++++++++++++++++++++++++
         M pipes                               |       7 +++++--
         D statusline.sh                       |      29 -----------------------------
         A volume                              |      24 ++++++++++++++++++++++++
       
       9 files changed, 186 insertions(+), 110 deletions(-)
       ---
 (DIR) diff --git a/battery b/battery
       t@@ -0,0 +1,55 @@
       +#!/bin/sh
       +#
       +# beep once per level. does not beep when charging
       +
       +# get battery level and status (charging or not)
       +BATC=`cat /sys/class/power_supply/BAT1/capacity`
       +BATS=`cat /sys/class/power_supply/BAT1/status`
       +
       +# Run this if sound is enabled
       +sbell () { 
       +    IFS=' %' read level state <<< `~/bin/volume`
       +
       +    ~/bin/volume unmute
       +    ~/bin/volume '80%'
       +
       +    beep -f 1000 -l 200 -D 50
       +
       +    case $state in
       +        on) ~/bin/volume unmute;;
       +        off) ~/bin/volume mute;;
       +    esac
       +
       +    # reset volume to its previous state
       +    ~/bin/volume "${level}%"
       +}
       +
       +# and this in case of no sound enabled
       +vbell () {
       +    $HOME/bin/popup "%{F#d43f10}battery $BATC%%"
       +}
       +
       +usage () {
       +    echo "usage: `basename $0` [<low> <critical> <dead>]"
       +    exit 1
       +}
       +
       +level () {
       +    echo "$BATC%"
       +    exit 0
       +}
       +
       +# If no argurments, return battery level
       +test "$#" -eq 0 && level
       +
       +# if less than 3 args, learn how to use, dumb
       +test "$#" -lt 3 && usage
       +
       +# if battery is charging, do not alert user
       +test "$BATS" == "Charging" && exit
       +
       +test $BATC -lt $1 && sbell # one bip for level <low>
       +test $BATC -lt $2 && sbell # two bip for level <critical>
       +test $BATC -lt $3 && sbell # battery is <dead>, bip 3 times
       +
       +test $BATC -lt $1 && vbell # popup a notification under <low> level
 (DIR) diff --git a/battery.sh b/battery.sh
       t@@ -1,42 +0,0 @@
       -#!/bin/sh
       -#
       -# beep once per level. does not beep when charging
       -
       -# get battery level and status (charging or not)
       -BATC=`cat /sys/class/power_supply/BAT1/capacity`
       -BATS=`cat /sys/class/power_supply/BAT1/status`
       -
       -# Run this if sound is enabled
       -sbell () { 
       -    beep -f 1000 -l 200 -D 50
       -}
       -
       -# and this in case of no sound enabled
       -vbell () {
       -    $HOME/bin/popup "\f1battery $BATC%"
       -}
       -
       -usage () {
       -    echo "usage: `basename $0` [<low> <critical> <dead>]"
       -    exit 1
       -}
       -
       -level () {
       -    echo "$BATC%"
       -    exit 0
       -}
       -
       -# If no argurments, return battery level
       -test "$#" -eq 0 && level
       -
       -# if less than 3 args, learn how to use, dumb
       -test "$#" -lt 3 && usage
       -
       -# if battery is charging, do not alert user
       -test "$BATS" == "Charging" && exit
       -
       -test $BATC -lt $1 && sbell  # one bip for level <low>
       -test $BATC -lt $2 && sbell  # two bip for level <critical>
       -test $BATC -lt $3 && sbell  # battery is <dead>, bip 3 times
       -
       -test $BATC -lt $1 && vbell # popup a notification under <low> level
 (DIR) diff --git a/dualhead.sh b/dualhead
 (DIR) diff --git a/gamma.sh b/gamma
 (DIR) diff --git a/instagram b/instagram
       t@@ -7,17 +7,16 @@
        # >> http://www.wtfpl.net/txt/copying/
        #
        
       -IMAGE_DIR=~/usr/img
       +VIEWER=meh
        EXEC_UPLOAD=~/bin/imgurup
       -SSHOT_DIR=${IMAGE_DIR}/wm
       +SSHOT_DIR=$PWD
        WMNAME=`xprop -root WM_NAME|cut -d\" -f2`
        
       -function upload() {
       +upload() {
            $EXEC_UPLOAD $1
        }
        
       -
       -function usage() {
       +usage() {
            cat <<SHBLAH
        Usage : instagram [-tmuwh] [-g number] [-s screen] [filename.png]
            -t          : create thumbnail
       t@@ -25,7 +24,6 @@ Usage : instagram [-tmuwh] [-g number] [-s screen] [filename.png]
            -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 '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.
       t@@ -40,11 +38,7 @@ Configuration:
        SHBLAH
        }
        
       -function upload() {
       -    $EXEC_UPLOAD $1
       -}
       -
       -function headshot() {
       +headshot() {
        
            xdpyinfo -ext XINERAMA | sed 's/^  head #//p' |
            while IFS=' :x@,' read i w h x y; do
       t@@ -54,27 +48,12 @@ function headshot() {
            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 8 -i :0.$SCREEN $SSHOT_DIR/tmp/record.mkv
       -    ffmpeg -i $SSHOT_DIR/tmp/record.mkv -t 0:0:5 -f image2 $SSHOT_DIR/tmp/%03d.jpg
       -    convert -delay 10 $SSHOT_DIR/tmp/*.jpg -coalesce -layers OptimizeTransparency $1
       -
       -    rm -rf $SSHOT_DIR/tmp/
       -}
       -
        [[ "$1" = "--help" ]] && usage && exit 0
        
        while getopts ":htmuwd:gs:" opt; do
            case $opt in
                t) THUMB=1 ;;
                d) SSHOT_DIR=$OPTARG ;;
       -        g) GIF=1 ;;
                s) SCREEN=$OPTARG ;;
                u) UPLOAD=1 ;;
                w) WINDOW=`xprop|grep 'window id'|cut -d\  -f7`;;
       t@@ -85,15 +64,10 @@ done
        
        shift $((OPTIND-1))
        
       -
        test -z $1 && OUTPUT=$WMNAME-`date +%Y-%m-%d`.png || OUTPUT=$1
        test -z "$WINDOW" && WINDOW='root'
        
       -if [ -n "$GIF" ]; then
       -    OUTPUT=${OUTPUT/.png/.gif}
       -    gifit $OUTPUT
       -elif [ -n "$SCREEN" ]; then
       -    #OUTPUT=head_$SCREEN-$OUTPUT
       +if [ -n "$SCREEN" ]; then
            headshot $SCREEN
        else
            import -window ${WINDOW} $SSHOT_DIR/$OUTPUT
       t@@ -102,9 +76,6 @@ fi
        test -n "$THUMB" && import -window ${WINDOW} -thumbnail 25% $SSHOT_DIR/thumb-${OUTPUT}
        
        
       -meh $SSHOT_DIR/$OUTPUT
       +$VIEWER $SSHOT_DIR/$OUTPUT
        
       -if [ "$UPLOAD" = "1" ]; then
       -    cd ${IMAGE_DIR}
       -    upload wm/${OUTPUT}
       -fi
       +test "$UPLOAD" = "1" && upload ${OUTPUT}
 (DIR) diff --git a/mkbar b/mkbar
       t@@ -0,0 +1,94 @@
       +#!/bin/sh
       +#
       +# z3bra - (c) wtfpl 2014
       +# Fetch infos on your computer, and print them to stdout every second.
       +
       +# configuration variables
       +refresh_rate=0.75               # how often will the bar update
       +datefmt="%H:%M"                 # date time format
       +maildir=~/var/mail/INBOX/new    # where do new mails arrive ?
       +battery=1                       # battery index
       +alsactl=Master                  # which alsa channel to display
       +no_group="░░"                   # Hidden groups
       +cur_group="██"       # current group
       +
       +# no need to modify anything else here
       +
       +clock() {
       +    date "+${datefmt}"
       +}
       +
       +mails() {
       +    fcount ${maildir}
       +}
       +
       +battery() {
       +    BATC=/sys/class/power_supply/BAT${battery}/capacity
       +    BATS=/sys/class/power_supply/BAT${battery}/status
       +
       +    # prepend percentage with a '+' if charging, '-' otherwise
       +    test "`cat $BATS`" = "Charging" && echo -n '+' || echo -n '-'
       +
       +    # append the character '%' after the number
       +    sed 's/$/%%/' $BATC
       +}
       +
       +volume() {
       +    amixer get $alsactl | sed -n 's/^.*\[\([0-9]\+%\).*$/\1%/p' | uniq
       +}
       +
       +cpuload() {
       +    LINE=`ps -eo pcpu |grep -vE '^\s*(0.0|%CPU)' |sed -n '1h;$!H;$g;s/\n/ +/gp'`
       +    echo `bc <<< $LINE`%%
       +}
       +
       +memused() {
       +    read t f <<< `grep -E 'Mem(Total|Free)' /proc/meminfo |awk '{print $2}'`
       +    echo `bc <<< "scale=2; 100 - $f / $t * 100" | cut -d. -f1`%%
       +}
       +
       +network() {
       +    read lo int1 int2 <<< `ip link | sed -n 's/^[0-9]: \(.*\):.*$/\1/p'`
       +    if iwconfig $int1 >/dev/null 2>&1; then
       +        wifi=$int1
       +        eth0=$int2
       +    else
       +        wifi=$int2
       +        eth0=$int1
       +    fi
       +    ip link show $eth0 | grep 'state UP' >/dev/null && int=$eth0 || int=$wifi
       +
       +    ping -c 1 8.8.8.8 >/dev/null 2>&1 && 
       +        echo "$int up" || echo "$int down"
       +}
       +
       +groups() {
       +    cur=`xprop -root _NET_CURRENT_DESKTOP | awk '{print $3}'`
       +    tot=`xprop -root _NET_NUMBER_OF_DESKTOPS | awk '{print $3}'`
       +
       +    for w in `seq 0 $((cur - 1))`; do line="${line}${no_group}"; done
       +    line="${line}${cur_group}"
       +    for w in `seq $((cur + 2)) $tot`; do line="${line}${no_group}"; done
       +    echo $line
       +}
       +
       +nowplaying() {
       +    cur=`mpc current`
       +    # this line allow to choose whether the output will scroll or not
       +    test "$1" = "scroll" && PARSER='skroll -n20 -d0.5 -r' || PARSER='cat'
       +    test -n "$cur" && $PARSER <<< $cur || echo "- stopped -"
       +}
       +
       +# This loop will fill a buffer with our infos, and output it to stdout.
       +while :; do
       +    buf="%{l} "
       +    buf="${buf} $(groups)%{U-}%{B-}%{F-}%{r}"
       +    buf="${buf} %{F#4c4c4c} CLK: %{F#ffffff}$(clock) "
       +    buf="${buf} %{F#4c4c4c} NET: %{F#ffffff}$(network) "
       +    buf="${buf} %{F#4c4c4c} CPU: %{F#ffffff}$(cpuload) "
       +    buf="${buf} %{F#4c4c4c} RAM: %{F#ffffff}$(memused) "
       +    buf="${buf} %{F#4c4c4c} VOL: %{F#ffffff}$(volume)  "
       +
       +    echo $buf
       +    sleep ${refresh_rate}
       +done
 (DIR) diff --git a/pipes b/pipes
       t@@ -9,13 +9,15 @@ declare -ar v=( [00]="\x83" [01]="\x8f" [03]="\x93"
                [30]="\x97" [32]="\x8f" [33]="\x81" )
        
        OPTIND=1
       -while getopts "f:s:r:h" arg; do
       +while getopts "cf:s:r:h" arg; do
        case $arg in
       +    c) COLOR=true;;
            f) ((f=($OPTARG>19 && $OPTARG<101)?$OPTARG:$f));;
            s) ((s=($OPTARG>4 && $OPTARG<16 )?$OPTARG:$s));;
            r) ((r=($OPTARG>0)?$OPTARG:$r));;
            h) echo -e "Usage: pipes [OPTION]..."
                echo -e "Animated pipes terminal screensaver.\n"
       +        echo -e " -c\t\tUse random colors for pipes"
                echo -e " -f [20-100]\tframerate (D=75)."
                echo -e " -s [5-15]\tprobability of a straight fitting (D=13)."
                echo -e " -r LIMIT\treset after x characters (D=2000)."
       t@@ -44,7 +46,8 @@ while ! read -t0.0$((1000/$f)) -n1; do
        
            # Print:
            tput cup $y $x
       -    echo -ne "\033[1;3${c}m\xe2\x94${v[$l$n]}"
       +    test "$COLOR" = "true" && echo -ne "\033[1;3${c}m"
       +    echo -ne "\xe2\x94${v[$l$n]}"
            (($t>$r)) && tput reset && tput civis && t=0 || ((t++))
            l=$n
        done
 (DIR) diff --git a/statusline.sh b/statusline.sh
       t@@ -1,29 +0,0 @@
       -#!/bin/bash
       -#
       -# status line for tmux.
       -# prints out a line formatted for tmux status.
       -
       -
       -w='#[fg=yellow,bold]'
       -B='#[fg=black,bold]'
       -
       -SEP="$w»$B"
       -# SEP="$w>$B>$B"
       -
       -
       -TEMP=$(acpi -t | awk '{print $4}')
       -LOAD=$(uptime | sed 's/^.*average: \([^ ]*\),.*$/\1/')
       -TIME=$(date "+%H:%M")
       -DATE=$(date "+%a%d")
       -
       -ramused() {
       -    ramtotal=$(free -m| sed -n '2p'| awk '{print $2}')
       -    ramused=$(free -m| sed -n '3p'| awk '{print $3}')
       -
       -    ram_perc=$(( 100*$ramused/$ramtotal ))
       -    echo $ram_perc
       -}
       -
       -
       -echo "$B$(ramused)% $SEP $LOAD $SEP $TEMP°C $SEP $DATE $w$TIME"
       -
 (DIR) diff --git a/volume b/volume
       t@@ -0,0 +1,24 @@
       +#!/bin/sh
       +#
       +# z3bra - (c) wtfpl 2014
       +# Manage ALSA Master channel
       +
       +test "$1" = "-h" && echo "usage `basename $0` [+|-|!]" && exit 0
       +
       +level() {
       +    amixer get Master | sed -n 's/^.*\[\([0-9]\+%\).*$/\1/p' | uniq
       +}
       +
       +state() {
       +    amixer get Master | sed -n 's/^.*\[\(o[nf]\+\)]$/\1/p' | uniq
       +}
       +
       +test $# -eq 0 && echo "`level` `state`" && exit 0
       +
       +case $1 in
       +    +)      amixer set Master 5%+ >/dev/null;;
       +    -)      amixer set Master 5%- >/dev/null;;
       +    !)      amixer set Master toggle >/dev/null;;
       +    *)    amixer set Master $1 >/dev/null;;
       +esac
       +