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 476ec4b15877a3bd7c7bbcc6ff667ab74e859058
(DIR) parent 5fdc8104beba6118ebd87f671da89fced5ae231b
(HTM) Author: z3bra <willy@mailoo.org>
Date: Fri, 4 Jul 2014 23:30:47 +0200
Merge branch 'master' of z3bra.org:scripts
Conflicts:
mkbar
popup
Diffstat:
M battery | 90 +++++++++++++++----------------
M cdump | 1 +
A chrono | 15 +++++++++++++++
A cpuload | 21 +++++++++++++++++++++
M hm | 2 +-
A human | 67 +++++++++++++++++++++++++++++++
M imgurup | 3 ++-
A memory | 62 +++++++++++++++++++++++++++++++
M mkbar | 14 +++++++-------
A network | 57 +++++++++++++++++++++++++++++++
M popup | 24 +++++++++++++-----------
M volume | 27 ++++++++++++++++++++-------
A xgroups | 70 +++++++++++++++++++++++++++++++
A xscreen | 25 +++++++++++++++++++++++++
14 files changed, 404 insertions(+), 74 deletions(-)
---
(DIR) diff --git a/battery b/battery
t@@ -1,61 +1,57 @@
#!/bin/sh
#
-# beep once per level. does not beep when charging
+# z3bra - (c) wtfpl 2014
-# get battery name
-BATN=$(ls /sys/class/power_supply/ | grep BAT)
-
-# exit if no battery available
-test -z "$BATN" && exit 1
-
-# get battery level and status (charging or not)
-BATC=`cat /sys/class/power_supply/$BATN/capacity`
-BATS=`cat /sys/class/power_supply/$BATN/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}%"
+usage () {
+ cat <<EOF
+usage: $(basename $0) [-hlsb]
+ -h : print this help
+ -l : print battery percentage (default)
+ -s : print battery state
+ -b : beep under critical level (see BAT_BELL)
+
+environment:
+ CRITICAL : the critical state level
+ BAT_BELL : the command to run when run with -b flag under CRITICAL level
+EOF
}
-# and this in case of no sound enabled
-vbell () {
- $HOME/bin/popup "%{F#d43f10}battery $BATC%%"
-}
+# if battery is under a critical level, $BAT_BELL will be run
+bell () {
+ # don't do anything if we're over the critical level, or the battery is
+ # charging
+ test ${BATC} -gt ${CRITICAL} && return 0
+ test ${BATS} != "Discharging" && return 0
-usage () {
- echo "usage: `basename $0` [<low> <critical> <dead>]"
- exit 1
+ $BAT_BELL
}
+# output the current battery level
level () {
- echo "$BATC%"
- exit 0
+ echo "${BATC}%"
}
-# If no argurments, return battery level
-test "$#" -eq 0 && level
-
-# if less than 3 args, learn how to use, dumb
-test "$#" -lt 3 && usage
+# print the current battery state
+state () {
+ echo "${BATS}"
+}
-# if battery is charging, do not alert user
-test "$BATS" = "Charging" && exit
+# get battery name
+BATN=$(ls /sys/class/power_supply/ | grep BAT)
-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
+# exit if no battery available
+test -z "$BATN" && exit 1
-test $BATC -lt $1 && vbell # popup a notification under <low> level
+# get battery level and status (charging or not)
+BATC=`cat /sys/class/power_supply/${BATN}/capacity`
+BATS=`cat /sys/class/power_supply/${BATN}/status`
+
+CRITICAL=${CRITICAL:-7}
+BAT_BELL=${BAT_BELL:-beep -f 1000 -l 200}
+
+case $1 in
+ -h) usage ;;
+ -s) state ;;
+ -b) bell ;;
+ *) level ;;
+ esac
(DIR) diff --git a/cdump b/cdump
t@@ -1,6 +1,7 @@
#!/bin/sh
FILE=$HOME/etc/Xresources
+FILE=$HOME/etc/theme/bow
for NUM in {0..7}; do
CN=$(grep "^\*color${NUM}:" $FILE | cut -d':' -f2 | tr -d ' ')
(DIR) diff --git a/chrono b/chrono
t@@ -0,0 +1,15 @@
+#!/bin/sh
+
+# fonts: xsansb future smblock univers
+
+FONT=$1
+: ${FONT:="univers"}
+
+for m in $(seq 0 59); do
+ for s in $(seq 0 59); do
+ clear
+ echo
+ printf ' %02d : %02d' $m $s | toilet -f $FONT
+ sleep 1
+ done
+done
(DIR) diff --git a/cpuload b/cpuload
t@@ -0,0 +1,21 @@
+#!/bin/sh
+#
+# z3bra - (c) wtfpl 2014
+
+usage () {
+ cat <<EOF
+usage: $(basename $0) [-hp]
+ -h : print help
+ -p : percentage of cpu used (default)
+EOF
+}
+
+cpuperc () {
+ LINE=`ps -eo pcpu |grep -vE '^\s*(0.0|%CPU)' |sed -n '1h;$!H;$g;s/\n/ +/gp'`
+ echo "`bc <<< $LINE`%"
+}
+
+case $1 in
+ -h) usage;;
+ *) cpuperc;;
+esac
(DIR) diff --git a/hm b/hm
t@@ -12,7 +12,7 @@ default=config.def.h
# How to list files managed by hmgr
#listcmd='ls -1 --color=auto'
-listcmd='tree -L 1 --noreport'
+listcmd='tree -L 2 --noreport'
# Change output colors ?
color_conf='1;37' # colors for config files
(DIR) diff --git a/human b/human
t@@ -0,0 +1,67 @@
+#!/bin/sh
+#
+# z3bra - (c) wtfpl 2014
+
+usage () {
+ cat <<EOF
+usage: $(basename $0) [-hfbmgt] <number>
+ -h : print help
+ -f : detect best factorisation to use (default)
+ -b : force output in Bytes
+ -m : force output in Mio
+ -g : force output in Gio
+ -t : force output in Tio
+
+environment:
+ SCALE : set the number of decimals
+EOF
+}
+
+# choose the best factore depending on the number
+factorize () {
+ if [ $1 -gt 1073741824 ]; then
+ echo T
+ elif [ $1 -gt 1048576 ]; then
+ echo G
+ elif [ $1 -gt 1024 ]; then
+ echo M
+ else
+ echo B
+ fi
+}
+
+# perform calculation depending on expected format
+humanize () {
+
+ unit=$1
+ num=$2
+
+ case $unit in
+ M) pow=1 ;;
+ G) pow=2 ;;
+ T) pow=3 ;;
+ *) pow=0; unit= ;;
+ esac
+
+ num=`bc <<< "scale=${SCALE}; ${num} / (1024 ^ ${pow})"`
+
+ echo "${num}${unit}"
+}
+
+# Set the default number of decimals
+SCALE=${SCALE:-0}
+
+case $1 in
+ -h) usage;;
+ -b) humanize B $2 ;;
+ -m) humanize M $2 ;;
+ -g) humanize G $2 ;;
+ -t) humanize T $2 ;;
+ *)
+ # this script require at least one argument
+ test $# -lt 1 && usage && exit 1
+
+
+ humanize $(factorize $1) $1
+ ;;
+ esac
(DIR) diff --git a/imgurup b/imgurup
t@@ -12,6 +12,7 @@ for F in "$@"; do
done
LOG=$HOME/.imgurlog
+CLIP="xsel -p -i"
# from http://imgur.com/tools/imgurbash.sh
APIKEY='b3625162d3418ac51a9ee805b1840452'
t@@ -24,7 +25,7 @@ for IMG in "$@"; do
URL=$(echo $RESP | sed 's|.*<original_image>\(.*\)</original_image>.*|\1|')
DELETEURL=$(echo $RESP | sed 's|.*<delete_page>\(.*\)</delete_page>.*|\1|')
- echo "$URL" >> $LOG
+ tee $LOG <<< "$URL" | $CLIP
echo "$DELETEURL" >> $LOG
echo "$URL"
done
(DIR) diff --git a/memory b/memory
t@@ -0,0 +1,62 @@
+#!/bin/sh
+#
+# z3bra - (c) wtfpl 2014
+
+usage () {
+ cat <<EOF
+usage: $(basename $0) [-hptu]
+ -h : print help
+ -p : percentage of memory used (default)
+ -t : total available memory
+ -u : memory used (human-readable)
+EOF
+}
+
+# display the total of available memory in human readable format
+memtotal () {
+ read mem <<< `grep -E 'MemTotal' /proc/meminfo |awk '{print $2}'`
+
+ if [ $mem -gt 1048576 ]; then
+ mem=`bc <<< "scale=2; $mem / 1048576"`
+ mem="${mem}G"
+ elif [ $mem -gt 1024 ]; then
+ mem=`bc <<< "$mem / 1024"`
+ mem="${mem}M"
+ fi
+
+ echo $mem
+}
+
+# display the memory used in human readable format
+memused () {
+ read t f <<< `grep -E 'Mem(Total|Free)' /proc/meminfo |awk '{print $2}'`
+ read b c <<< `grep -E '^(Buffers|Cached)' /proc/meminfo |awk '{print $2}'`
+ mem=`bc <<< "($t - $f - $c - $b)"`
+
+ if [ $mem -gt 1048576 ]; then
+ mem=`bc <<< "scale=2; $mem / 1048576"`
+ mem="${mem}G"
+ elif [ $mem -gt 1024 ]; then
+ mem=`bc <<< "$mem / 1024"`
+ mem="${mem}M"
+ fi
+
+ echo $mem
+}
+
+# display the memory used in percentage
+memperc () {
+ read t f <<< `grep -E 'Mem(Total|Free)' /proc/meminfo |awk '{print $2}'`
+ read b c <<< `grep -E '^(Buffers|Cached)' /proc/meminfo |awk '{print $2}'`
+ mem=`bc <<< "100 * ($t - $f - $c - $b) / $t"`
+
+ echo "${mem}%"
+}
+
+
+case $1 in
+ -h) usage;;
+ -t) memtotal;;
+ -u) memused;;
+ *) memperc;;
+ esac
(DIR) diff --git a/mkbar b/mkbar
t@@ -15,7 +15,7 @@
# configuration variables
refresh_rate=0.75 # how often will the bar update
-datefmt="%H:%M - %d %b" # date time format
+datefmt="%d %b %H:%M" # date time format
maildir=~/var/mail/INBOX/new # where do new mails arrive ?
alsactl=Master # which alsa channel to display
#battery=BAT0 # battery index
t@@ -24,12 +24,12 @@ battery=$(ls /sys/class/power_supply | grep BAT)
barch=''
barfg='%{F#ff666666}'
-barmg='%{F#ff222222}'
-barbg='%{F#ffcccccc}'
+barmg='%{F#ff2288cc}'
+barbg='%{F#00888888}'
-grpfg='%{F#ff333333} '
-grpmg='%{F#ff666666} '
-grpbg='%{F#ffaaaaaa} '
+grpfg='%{F#ff111111} '
+grpmg='%{F#ff2288cc} '
+grpbg='%{F#ffbbbbbb} '
# no need to modify anything else here
t@@ -120,7 +120,7 @@ groups() {
for w in `seq 0 $((cur - 1))`; do line="${line}${grpbg}"; done
line="${line}${grpfg}"
for w in `seq $((cur + 2)) $tot`; do line="${line}${grpbg}"; done
- line="${line}%{F-}"
+ line="${line}${barfg}"
echo $line
}
(DIR) diff --git a/network b/network
t@@ -0,0 +1,57 @@
+#!/bin/sh
+#
+# z3bra - (c) wtfpl 2014
+
+usage () {
+ cat <<EOF
+usage: $(basename $0) [-hicwdu]
+ -h : print help
+ -i : print out current interface
+ -c : return 0 if connected to a network (default)
+ -w : return 0 if connected over wifi
+ -d : print out size of downloaded packets
+ -u : print out size of uploaded packets
+EOF
+}
+
+# get current interface
+netint() {
+ for int in $(ls /sys/class/net); do
+ if grep -q ${int} /proc/net/route; then
+ echo ${int}
+ return 0
+ fi
+ done
+
+ # no interface up, return loopback
+ echo "lo"
+}
+
+netstate () {
+ grep -q $(netint) /proc/net/route && return 0 || return 1
+}
+
+wireless () {
+ grep -q $(netint) /proc/net/wireless && return 0 || return 1
+}
+
+# get upload/download traffic
+nettraffic() {
+ case $1 in
+ up) col=10 ;;
+ *) col=2 ;;
+ esac
+
+ traffic=$(awk "/$(netint)/ {print \$$col}" /proc/net/dev)
+
+ human ${traffic}
+}
+
+case $1 in
+ -h) usage ;;
+ -i) netint ;;
+ -w) wireless ;;
+ -d) nettraffic down ;;
+ -u) nettraffic up ;;
+ *) netstate ;;
+ esac
(DIR) diff --git a/popup b/popup
t@@ -9,27 +9,28 @@ SLEEP=3
# bar options
font='-*-stlarch-medium-r-*-*-10-*-*-*-*-*-*-*'
font="$font,-*-gohufont-medium-*-*--11-*-*-*-*-*-iso10646-1"
-bg="#ffeeeeee"
-fg="#ff888888"
-hl="#ff333333"
+bg="#ff333333"
+fg="#ffffffff"
+hl="#ff2288cc"
IFS=' x' read x y <<< `xrandr | grep '*' | sed 1q | awk '{print $1}'`
-width=144
-height=20
+width=300
+height=30
offx=$(( x/2 - $width - 74 ))
-offx=740
-offy=10
+offx=1610
+offy=1040
+title=""
geom=${width}x${height}+${offx}+${offy}
usage() {
- echo "`basename $0` [-hb] [-d delay] [-g WxH+X+Y] [TEXT]"
+ echo "`basename $0` [-hb] [-d delay] [-t title] [-g WxH+X+Y] [TEXT]"
}
spawn() {
- prefix='%{F#fffffe00} %{F-}'
- (echo "%{l}${prefix} $@";sleep $SLEEP) | bar -g $geom -f $font -B $bg -F $fg
+ prefix="%{F${hl}} ${title} %{F-}"
+ (echo "%{l}${prefix} %{r}$@ ";sleep $SLEEP) | bar -g $geom -f $font -B $bg -F $fg
}
loop() {
t@@ -105,12 +106,13 @@ group() {
test "$#" -lt 1 && exit 1
-while getopts ":bd:g:hl" opt; do
+while getopts ":bd:g:hlt:" opt; do
case $opt in
b) BEEP=1 ;;
l) LOOP=1 ;;
d) SLEEP=$OPTARG ;;
g) geom=$OPTARG ;;
+ t) title=$OPTARG ;;
h) usage; exit 0 ;;
*) usage; exit 1 ;;
esac
(DIR) diff --git a/volume b/volume
t@@ -1,9 +1,19 @@
#!/bin/sh
#
# z3bra - (c) wtfpl 2014
-# Manage ALSA Master channel
-test "$1" = "-h" && echo "usage `basename $0` [+|-|!]" && exit 0
+usage () {
+ cat <<EOF
+usage: $(basename $0) [-hsla] [-+!]
+ -h : print help
+ -s : print on/off
+ -l : print the current volume percentage
+ -a : print both level and state (default)
+ + : volume +5%
+ - : volume -5%
+ ! : toggle mute
+EOF
+}
level() {
amixer get Master | sed -n 's/^.*\[\([0-9]\+%\).*$/\1/p' | uniq
t@@ -13,12 +23,15 @@ state() {
amixer get Master | sed -n 's/^.*\[\(o[nf]\+\)]$/\1/p' | uniq
}
+# print out level and state if no argument is given
test $# -eq 0 && echo "`level` `state`" && exit 0
case $1 in
- +) amixer set Master 5%+ >/dev/null;;
- -) amixer set Master 5%- >/dev/null;;
- level|state) $1;;
- !) amixer set Master toggle >/dev/null;;
- *) amixer set Master $1 >/dev/null;;
+ -h) usage ;;
+ -s) state ;;
+ -l) level ;;
+ +) 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
(DIR) diff --git a/xgroups b/xgroups
t@@ -0,0 +1,70 @@
+#!/bin/sh
+#
+# z3bra - (c) wtfpl 2014
+
+usage () {
+ cat <<EOF
+usage: $(basename $0) [-hta]
+ -h : print help
+ -c : print the current group number (default)
+ -t : print the number of groups
+ -a : print all groups
+
+environment:
+ GRP_CURRENT : look of current dekstop
+ GRP_HAZWIN : look of desktop holding windows
+ GRP_EMPTY : look of empty groups
+ SEPARATOR : group separator (on the right of each desktop)
+EOF
+}
+
+# display the current group
+current () {
+ xprop -root _NET_CURRENT_DESKTOP | awk '{print $3}'
+}
+
+# display the total number of groups
+total () {
+ xprop -root _NET_NUMBER_OF_DESKTOPS | awk '{print $3}'
+}
+
+# print current group and shown groups
+fullbar () {
+ cur=$(current)
+ tot=$(total)
+ max=$((tot - 1))
+
+ # create a list containing the groups holding at least one window
+ for wid in `xprop -root | sed '/_LIST(WINDOW)/!d;s/.*# //;s/,//g'`; do
+ # uncomment this "if" statement to show groups only if their windows
+ # are visible
+ #if grep -q 'IsViewable' <<< $(xwininfo -id $wid); then
+ grp=`xprop -id $wid _NET_WM_DESKTOP | awk '{print $3}'`
+ shown="$shown $grp"
+ #fi
+ done
+
+ # create a bar containing all desktops
+ for g in `seq 0 ${max}`; do
+ if test $g -eq $cur; then l="${l}${GRP_CURRENT}"
+ elif grep -q $g <<<"$shown"; then l="${l}${GRP_HAZWIN}"
+ else l="${l}${GRP_EMPTY}"
+ fi
+
+ test ${g} -lt ${max} && l="${l}${SEPARATOR}"
+ done
+
+ echo "$l"
+}
+
+GRP_CURRENT=${GRP_CURRENT:-*}
+GRP_HAZWIN=${GRP_HAZWIN:-+}
+GRP_EMPTY=${GRP_EMPTY:--}
+SEPARATOR=${SEPARATOR:- }
+
+case $1 in
+ -h) usage ;;
+ -t) total ;;
+ -a) fullbar ;;
+ *) current ;;
+ esac
(DIR) diff --git a/xscreen b/xscreen
t@@ -0,0 +1,25 @@
+#!/bin/sh
+#
+# z3bra - (c) wtfpl 2014
+
+usage () {
+ cat <<EOF
+usage: $(basename $0) [-hptu]
+ -h : height of the screen
+ -w : width of the screen
+ -g : print full size (default)
+
+environment:
+ SCREEN : number of the screen to parse
+EOF
+}
+
+
+IFS='x' read w h <<< "$(xrandr | awk '/\*/ {print $1}' | sed -n ${SCREEN}p)"
+
+case $1 in
+ --help) usage ;;
+ -h) echo $h ;;
+ -w) echo $w ;;
+ *) echo ${w}x${h} ;;
+ esac