scripts

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

commit 1a93d39ffc86acf43f9abcde01e955b1ecfe403d
parent db5a243a3233cb0a78cf0db0bfedd64d7c103772
Author: z3bra <willy@mailoo.org>
Date:   Fri Mar 28 09:53:50 +0100

Merge branch 'master' of z3bra.org:scripts

Diffstat:
battery.sh | 43++++++++++++++++++++++++++++++++++---------
cdump | 2+-
deptree.sh | 47+++++++++++++++++++++++++++++++++++++++++++++++
gamma.sh | 24++++++++++++++++++++++++
img | 7+++++++
imgt | 5++++-
imgurup | 30++++++++++++++++++++++++++++++
info.sh | 25+++++++++++--------------
menu | 19+++++++++++++++++++
popup | 126++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---------
prtmk | 73+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
q3dl | 23+++++++++++++++++++++++
rclick.menu | 33+++++++++++++++++++++------------
translate | 30++++++++++++++++++++++++++++++
upload | 2+-
utf8.sh | 52++++++++++++++++++++++++++++++++++++++++++++++++++++
ypl | 10++++++++++
17 files changed, 500 insertions(+), 51 deletions(-)
diff --git a/battery.sh b/battery.sh @@ -1,17 +1,42 @@ #!/bin/sh # -# Beep once when under 15%, twice under 10, and three times under 5% -# Under 3%, you're asked to shutdown +# 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 -if test $BATC -gt 3; then - test $BATC -lt 15 && beep -f1000 -l200 -D50 - test $BATC -lt 10 && beep -f1000 -l200 -D50 - test $BATC -lt 5 && beep -f1000 -l200 -D50 -else - test $BATC -lt 3 && espeak 'Battery is empty, please shut down' -fi +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 diff --git a/cdump b/cdump @@ -1,6 +1,6 @@ #!/bin/sh -FILE=$HOME/.Xresources +FILE=$HOME/etc/Xresources for NUM in {0..7}; do CN=$(grep "color${NUM}:" $FILE | cut -d':' -f2 | tr -d ' ') diff --git a/deptree.sh b/deptree.sh @@ -0,0 +1,47 @@ +#!/bin/bash +# +# (c) wtfpl by z3bra +# deptree; List dependencies that are installed ONLY for <packages> + + +test $# -ne 1 && echo "`basename $0 <package>`" && exit 1 + +deplist='' +level=0 + +# needless to bother with any f**king locale here +export LC_ALL=en_US + +indent() { + for i in `seq 0 $1`; do + echo -n ' ' + done +} + +dependent() { + IFS=' ><=' read pkg version<<< "$1" + + exec 2>/dev/null + dep=`pacman -Qi $pkg | grep 'Required By' | sed 's/^.*: //'` + opt=`pacman -Qi $pkg | grep 'Optional Deps' | sed 's/^.*: //'` + + test "$dep" = "None" && echo $opt || echo $dep +} + +deplist() { + IFS=' ><=' read pkg version<<< "$1" + + exec 2>/dev/null + pacman -Qi $pkg | grep 'Depends On' | sed 's/^.*: //' | grep -Ev 'None|--' +} + +listdep() { + list=`deplist $1 | sed 's/[<>=]*[.0-9]*//g'` + + for pkg in $list; do + isdep=`dependent $pkg` + test "$1" = "$isdep" && echo $pkg + done +} + +listdep $1 diff --git a/gamma.sh b/gamma.sh @@ -0,0 +1,24 @@ +#!/bin/sh + +usage () { + echo "usage: `basename $0` <get|up|down|reset> [value]" +} + +test "$#" -lt 1 && usage && exit +test -n "$2" && amount=$2 || amount=0.1 + +gamma=`grep RedGamma ~/.nvidia| cut -d= -f2` +old=$gamma + +case $1 in + get) echo $gamma; exit ;; + up) gamma=`bc <<< "$gamma + $amount"` ;; + down) gamma=`bc <<< "$gamma - $amount"` ;; + reset)gamma="1.000000" ;; + *) usage && exit ;; +esac + +echo "$old -> $gamma" + +nvidia-settings -a [DPY:DVI-I-0]/Gamma=$gamma >/dev/null +sed -i "/Gamma/s/$old/$gamma/" ~/.nvidia diff --git a/img b/img @@ -0,0 +1,7 @@ +#!/bin/sh + +IMAGE=/tmp/`basename $1` +echo "Downloading image.." +curl -s "$1" > $IMAGE +meh $IMAGE +rm $IMAGE diff --git a/imgt b/imgt @@ -8,11 +8,14 @@ W3MIMGDISPLAY="/usr/lib/w3m/w3mimgdisplay" FILENAME=$1 FONTH=14 # Size of one terminal row FONTW=8 # Size of one terminal column +BORDER=20 COLUMNS=`tput cols` LINES=`tput lines` read width height <<< `echo -e "5;$FILENAME" | $W3MIMGDISPLAY` +offx=$(($BORDER / $FONTH)) +offy=$(($BORDER / $FONTW)) max_width=$(($FONTW * $COLUMNS)) max_height=$(($FONTH * $LINES)) @@ -25,7 +28,7 @@ if test $height -gt $max_height; then height=$max_height fi -w3m_command="0;1;0;0;$width;$height;;;;;$FILENAME\n4;\n3;" +w3m_command="0;1;$offx;$offy;$width;$height;;;;;$FILENAME\n4;\n3;" clear tput cup $(($height/$FONTH)) 0 diff --git a/imgurup b/imgurup @@ -0,0 +1,30 @@ +#!/bin/sh + +# upload images to imgur.com +# appends links and deletion links to the log +# depends: curl + +# check if all args exist as files +for F in "$@"; do + if ! test -f "$F"; then + echo usage: $(basename $0) image ... && exit 1 + fi +done + +LOG=$HOME/.imgurlog + +# from http://imgur.com/tools/imgurbash.sh +APIKEY='b3625162d3418ac51a9ee805b1840452' + +# upload all +for IMG in "$@"; do + RESP=$(curl -F "image=@$IMG" -F "key=$APIKEY" \ + http://imgur.com/api/upload.xml 2> /dev/null) + + URL=$(echo $RESP | sed 's|.*<original_image>\(.*\)</original_image>.*|\1|') + DELETEURL=$(echo $RESP | sed 's|.*<delete_page>\(.*\)</delete_page>.*|\1|') + + echo "$URL" >> $LOG + echo "$DELETEURL" >> $LOG + echo "$URL" +done diff --git a/info.sh b/info.sh @@ -1,5 +1,8 @@ #!/bin/sh +gitdir=http://git.z3bra.org +myblog=http://blog.z3bra.org + c00=$'\e[0;30m' c01=$'\e[0;31m' c02=$'\e[0;32m' @@ -21,28 +24,22 @@ f0=$'\e[1;30m' f1=$'\e[1;37m' f2=$'\e[0;37m' -kernel=$(uname -rmo) -#cpuspe=$(grep 'model name' /proc/cpuinfo| sed 1q|sed 's/^.*:\ *//') -cpuspe=$(sed -n '/model\ name/s/^.*:\ //p' /proc/cpuinfo | uniq) - -#system=$(lsb_release -d | sed 's/^.*:\s*//') -system=$(cat /etc/issue|cut -d\\ -f1) +kernel=`uname -rmo` +cpuspe="`sed -n '/model\ name/s/^.*:\ //p' /proc/cpuinfo | uniq` (x`nproc`)" +system=`sed 's/\s*[\(\\]\+.*$//' /etc/issue` if [ -n "$DISPLAY" ]; then - wmname=$(xprop -root WM_NAME|cut -d\" -f2) - termfn=$(sed -n 's/^.*\*font:\ *-[a-z]*-\([^-]*\)-.*/\1/p' ~/.Xresources) - systfn=$(sed -n 's/^.*font.*"\(.*\)".*$/\1/p' ~/.gtkrc-2.0) + wmname=`xprop -root WM_NAME|cut -d\" -f2` + termfn=`sed -n 's/^.*\*font:\s* -\*-\([^-]*\)-.*/\1/p' ~/.Xresources` + systfn=`sed -n 's/^.*font.*"\(.*\)".*$/\1/p' ~/.gtkrc-2.0` else wmname="none" termfn="none" systfn="none" fi -pkgnum=$(pacman -Q|wc -l) -birthd=$(sed -n '1s/^\[\([0-9-]*\).*$/\1/p' /var/log/pacman.log | tr - .) - -gitdir=git.z3bra.org -myblog=blog.z3bra.org +pkgnum=`pacman -Q|wc -l` +birthd=`sed -n '1s/^\[\([0-9-]*\).*$/\1/p' /var/log/pacman.log | tr - .` cat << EOF ${c00}▉▉ | ${f1}OS ${f0}........... $f2$system diff --git a/menu b/menu @@ -0,0 +1,19 @@ +#!/bin/sh +X=1790 +Y=820 + +if which xdpyinfo >/dev/null; then + dimensions=`xdpyinfo -ext XINERAMA | grep 'head #0' | sed 's/^ head #//p'` + + IFS=' :x@,' read i w h x y <<< "$dimensions" +fi + +X=`expr ${w} - 120 - 10` +Y=`expr ${h} - 240 - 10` + +thingmenu -x -s -g 120x120+${X}+${Y} \ + "pop a terminal" "urxvt" \ + "browse the web" "surf || dwb" \ + "view a pdf" "mupdf || zathura" \ + "play a game" "steam" \ + "restart 2bwm" "pkill 2bwm; 2bwm" 2> /dev/null diff --git a/popup b/popup @@ -4,26 +4,126 @@ # Create a small popup with the given text TEXT='none' -GEOM="32x6+20+20" -PRETTY="toilet --gay -f smblock" -SLEEP=1 +SLEEP=3 -volume() { - VOLUME=`amixer sget Master | - sed -n 's/^.*\[\([0-9/]*%\)\].*\[\(o[nf]\+\)\]$/\1 (\2)/p'| uniq` - echo $VOLUME +# bar options +font="-*-gohufont-medium-*-*--11-*-*-*-*-*-iso10646-1" +bg="#1d1d1d" +fg="#ffffff" +hl="#4c4c4c" +width=120 +height=20 +offx=1790 +offy=790 + +usage() { + echo "`basename $0` [-hb] [-d delay] [-x offx] [-y offy] [-w width] [TEXT]" } spawn() { - #urxvt -geometry $GEOM -e sh -c "echo;echo ' $@'|$PRETTY; sleep $SLEEP" - (echo "\c\f8 $@";sleep $SLEEP)|bar -w 96 + (echo "%{c}$@";sleep $SLEEP) | bar -g $geom -f $font -B $bg -F $fg +} + +loop() { + (while :; do + echo "%{c}`$1`" + sleep $SLEEP + done) | bar -g $geom -f $font -B $bg -F $fg +} + +getvol() { + vol=`amixer sget Master | + sed -n 's/^.*\[\([0-9/]*%\)\].*\[\(o[nf]\+\)\]$/\1 (\2)/p' | + uniq` + case $1 in + value) echo $vol | sed 's/%.*$//' ;; + state) echo $vol | sed -n 's/^.*(\([onf]*\))/\1/p' ;; + *) echo $vol ;; + esac +} + +volume() { + test "`getvol state`" = "off" && echo -n "muted - " + echo -n "`getvol value`%%" +} + +volumebar() { + max=10 + cur=$((`getvol value` / max)) + + test "`getvol state`" = "off" && fg='#d43f10' + + for v in $(seq 1 $((max - 1))); do + if [ "$v" -lt "$cur" ]; then + val="$val%{F${fg}}━━" + else + val="$val%{F${hl}}━━" + fi + done + + echo -n "${val}" } -test -z "$1" && exit 1 +battery() { + BATC=`cat /sys/class/power_supply/BAT1/capacity` + BATS=`cat /sys/class/power_supply/BAT1/status` + echo "$BATC%% ($BATS)" +} + +mail() { + echo "`fcount ~/var/mail/INBOX/new` new mail!" +} + +date() { + date "+%d/%m/%y \(%H:%M\)" +} + +group() { + cur=`xprop -root _NET_CURRENT_DESKTOP | awk '{print $3}'` + num=`xprop -root _NET_NUMBER_OF_DESKTOPS | awk '{print $3}'` + + val='' + + for w in $(seq 1 $((num - 1))); do + if [ "$w" -eq "$cur" ]; then + val="$val%{F${fg}}━━" + else + val="$val%{F${hl}}━━" + fi + done + + echo -n "${val}" +} + +test "$#" -lt 1 && exit 1 + +while getopts ":bd:hlw:x:y:" opt; do + case $opt in + b) BEEP=1 ;; + l) LOOP=1 ;; + d) SLEEP=$OPTARG ;; + w) width=$OPTARG ;; + x) offx=$OPTARG ;; + y) offy=$OPTARG ;; + h) usage; exit 0 ;; + *) usage; exit 1 ;; + esac +done + +geom=${width}x${height}+${offx}+${offy} + +shift $(( OPTIND - 1 )); case $1 in - volume) TEXT=`volume`;; - *) TEXT=$@;; + volumebar|volume|battery|mail|date|group) + TEXT=`$1` + FUNC="$1" ;; + *) + TEXT="$@" + FUNC="echo $TEXT" + ;; esac -spawn "$TEXT" +# can be *REALLY* annoying +test -n "$BEEP" && beep -f 1500 -d 20 -l 100 +test -n "$LOOP" && loop "$FUNC" || spawn "$TEXT" diff --git a/prtmk b/prtmk @@ -0,0 +1,73 @@ +#!/bin/sh + +PKGFILE=~/src/ports/Pkgfile +PORTDIR=~/usr/ports +test -z $EDITOR && EDITOR=vim + +echo_color () { + tput bold + tput setaf $1 + shift + + echo "$@" + + tput sgr0 +} + +read -p 'Name : ' name +read -p 'Description : ' description +read -p 'Version : ' version +read -p 'URL : ' url +read -p 'Maintainer : ' daddy +read -p 'Depends on : ' depends +read -p 'Source : ' sources + +source=${source/$name/\$name} +source=${source/$version/\$version} + +PORTDIR=$PORTDIR/$name + +if test "$version" = "git"; then + git_url=$sources + sources='' + + PKGFILE=${PKGFILE}-git + PORTDIR=${PORTDIR}-git +fi + +echo -n "creating port $name .. " +mkdir $PORTDIR + +if cd $PORTDIR; then + echo_color 2 OK +else + echo_color 1 FAIL + exit 1 +fi + +echo -n "copying Pkgfile .. " +cp $PKGFILE Pkgfile + +if test -f $PORTDIR/Pkgfile; then + echo_color 2 OK +else + echo_color 1 FAIL + exit 1 +fi + +echo -n "filling Pkgfile .. " +sed \ + -e "s__DESCRIPTION__$description" \ + -e "s__URL__$url" \ + -e "s__MAINTAINER__$daddy" \ + -e "s__DEPENDENCIES__$depends" \ + -e "s__NAME__$name" \ + -e "s__VERSION__$version" \ + -e "s__SOURCE__$sources" \ + -e "s__GIT_URL__$git_url" \ + -i $PORTDIR/Pkgfile +echo_color 2 OK + +echo -n "openning Pkgfile for fixes .. " +$EDITOR Pkgfile +echo_color 2 OK diff --git a/q3dl b/q3dl @@ -0,0 +1,23 @@ +#!/bin/sh + +q3df='http://ws.q3df.org/maps/downloads' +map=$1 + +W="\033[1;37m" +R="\033[1;31m" +G="\033[1;32m" +N="\033[0m" + +echo -ne "Fetching map ${W}${map}.pk3 ${N}.. " + +curl -s "${q3df}/${map}.pk3" > /tmp/q3map.zip + +if unzip -p /tmp/q3map.zip >/dev/null 2>&1 ; then + mv /tmp/q3map.zip ~/.q3a/baseq3/${map}.pk3 + echo -e "[${G}DONE${N}]" +else + echo -e "[${R}FAIL${N}]" + rm /tmp/q3map.zip +fi + +exit 0 diff --git a/rclick.menu b/rclick.menu @@ -1,15 +1,24 @@ #!/usr/bin/9menu -file -popup -geometry 8x16 --font -misc-tamsyn-medium-r-normal--14-101-100-100-c-70-iso8859-1 -tmnl:urxvt -fluid:fluid - --- :true -mail:urxvt -e mutt -www:surf http://duckduckgo.com/lite -rdktp:srv mdc97302 -vnc:vnc-E4_6_3-x64_linux_viewer - --- :true -restart:pkill 2bwm;2bwm -quit:pkill xclock -off:poweroff +-font -misc-tamsyn-medium-r-normal--12-87-100-100-c-60-iso8859-1 + COMMON ---- :true + tmnl :urxvt + www :dwb + mail :urxvt -e mutt + GAMES ----- :true + steam :steam + defrag :ioquake3 +set fs_game defrag + 2048 :surf http://gabrielecirulli.github.io/2048/ + teeworlds :teeworlds + sauerbraten :sauerbraten-client + WORK ------ :true + mstsc :~/bin/srv fic97302 + vnc :vncviewer + fltk :fluid ~/src/cpp/cico/src/fltk.fl + pdf :zathura || mupdf + SESSION --- :true + restart :pkill 2bwm;2bwm + quit :pkill xclock + reboot :reboot + power off :poweroff diff --git a/translate b/translate @@ -0,0 +1,30 @@ +#!/bin/sh + +# use the google translate service +# depends: curl + +if test -z "$1"; then + echo "usage: $(basename $0) text" + echo "examples:" + echo " $(basename $0) text" + echo " TL=el $(basename $0) text" + echo " SL=en TL=pl $(basename $0) text" + exit 1 +fi + +TEXT=$1 +SL=$(test -n "$SL" && echo "$SL" || echo auto) +TL=$(test -n "$TL" && echo "$TL" || echo en) + +TRANSLATEURL='http://translate.google.com/' +UA='Mozilla 5.0' +NEWLINE='\ +' + +# do translate +curl --user-agent "$UA" \ + --data "sl=$SL" \ + --data "tl=$TL" \ + --data-urlencode "text=$TEXT" \ + --silent $TRANSLATEURL \ + | sed "s/<\/span>/$NEWLINE/g" | grep 'result_box' | sed 's/.*>//' diff --git a/upload b/upload @@ -1,4 +1,4 @@ -#!/usr/bin/bash +#!/bin/bash host=gavroche user=willy diff --git a/utf8.sh b/utf8.sh @@ -0,0 +1,52 @@ +#!/bin/bash + +usage() { + + echo "`basename $0` [min max] (min, max: 0x0000..0xffff)" + +} + +fast_chr() { + local __octal + local __char + printf -v __octal '%03o' $1 + printf -v __char \\$__octal + REPLY=$__char +} + +function unichr { + local c=$1 # ordinal of char + local l=0 # byte ctr + local o=63 # ceiling + local p=128 # accum. bits + local s='' # output string + + (( c < 0x80 )) && { fast_chr "$c"; echo -n "$REPLY"; return; } + + while (( c > o )); do + fast_chr $(( t = 0x80 | c & 0x3f )) + s="$REPLY$s" + (( c >>= 6, l++, p += o+1, o>>=1 )) + done + + fast_chr $(( t = p | c )) + echo -n "$REPLY$s " +} + +min=0xe000 +max=0xe1a0 + +if test $# -gt 1; then + if test $# -eq 2; then + min=$1 + max=$2 + fi +else + usage + exit 1 +fi + +## test harness +for (( i=$min; i<$max; i++ )); do + unichr $i +done diff --git a/ypl b/ypl @@ -0,0 +1,10 @@ +#!/bin/sh +# See the LICENSE file for copyright and license details. + +MCMD="mplayer %u" +if [ -z "$CACA_DRIVER" -a -z "$DISPLAY" ]; +then + export CACA_DRIVER=ncurses + MCMD="mplayer -vo caca %u" +fi +quvi --exec "$MCMD" "$1"