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 2214a036f039481f0a15bda1dcb1c3ec95d4947f
(DIR) parent 1c4e8db6aade80762d93b00456a0f63e6dd7c23b
(HTM) Author: z3bra <willy@mailoo.org>
Date: Sun, 6 Jul 2014 16:13:44 +0200
Merge branch 'master' of z3bra.org:scripts
Diffstat:
M battery | 90 +++++++++++++++----------------
M cdump | 1 +
A chrono | 15 +++++++++++++++
A cpuload | 21 +++++++++++++++++++++
M dm | 5 +++--
A hm | 148 +++++++++++++++++++++++++++++++
D hmgr | 136 -------------------------------
A human | 67 +++++++++++++++++++++++++++++++
M imgurup | 3 ++-
M info.sh | 2 +-
A memory | 62 +++++++++++++++++++++++++++++++
M mkbar | 37 ++++++++++++++++---------------
A network | 57 +++++++++++++++++++++++++++++++
M popup | 22 ++++++++++++----------
M prtmk | 11 +++++++----
A prtup | 70 +++++++++++++++++++++++++++++++
M translate | 2 +-
M volume | 27 ++++++++++++++++++++-------
A xgroups | 70 +++++++++++++++++++++++++++++++
A xscreen | 25 +++++++++++++++++++++++++
20 files changed, 644 insertions(+), 227 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/dm b/dm
t@@ -6,14 +6,15 @@
sockdir=~/var/run
list() {
- ls -1 $sockdir --color=auto
+ # change colors, for fun!
+ ls -1 $sockdir
}
usage() {
echo "`basename $0` [-hl] <alias> [command]"
}
-while getopts "l" opt; do
+while getopts "hl" opt; do
case $opt in
l) list; exit 0 ;;
h) usage; exit 0 ;;
(DIR) diff --git a/hm b/hm
t@@ -0,0 +1,148 @@
+#!/bin/sh
+#
+# z3bra - (c) wtfpl 2014
+# Manage your config.h files on a per program basis. Store defaults and user
+# configs, and restore them easily.
+
+# Directory where configs are saved
+basedir=~/.hm.d
+
+# Default names for configs
+default=config.def.h
+
+# How to list files managed by hmgr
+#listcmd='ls -1 --color=auto'
+listcmd='tree -L 2 --noreport'
+
+# Change output colors ?
+color_conf='1;37' # colors for config files
+color_dirs='0;33' # colors for directory names
+
+
+usage() {
+echo "usage: $(basename $0) [-hu] [-l [dir]] [-di <file>] [-csr <dir>/<name>]"
+
+test -z "$1" && return
+
+cat <<EOF
+ -h : help
+ -u : shortcut for -n ${USER}.h
+
+ -l [dir] : list currently managed applications/files
+
+ -d <dir>/<name> : remove <name> from managed configs
+ -i <file> : input file to use (defaults to ./config.h)
+
+ -c <dir> : check which config is in use
+ -s <dir>/<name> : store \`config.h\` to <dir>/<name>
+ -r <dir>/<name> : restore \`config.h\` from <dir>/<name>
+EOF
+}
+
+store() {
+ test -z "$1" && return 1
+
+ # check if the user gave a filename or not
+ # and deduct filepath from that
+ if test `dirname $1` = '.'; then
+ dir=$1
+ filepath=${basedir}/${dir}/${default}
+ else
+ dir=`dirname $1`
+ filepath=${basedir}/$1
+ fi
+
+ # create directory if it does not exist
+ test ! -d ${basedir}/${dir} && mkdir -p ${basedir}/${dir}
+
+ # Copy from current dir to base directory
+ cp -i ${cin} ${filepath}
+}
+
+restore() {
+ test -z "$1" && return 1
+
+ if test -f ${basedir}/$1; then
+ filepath=${basedir}/$1
+ else
+ filepath=${basedir}/$1/${default}
+ fi
+
+ # Copy from base dir to current directory
+ cp ${filepath} ${cin}
+}
+
+list() {
+
+ # Go to the base directory
+ cd ${basedir}
+
+ ${listcmd} $1
+}
+
+check() {
+ found=0
+
+ test ! -f ${cin} && echo "cannot find file ${cin}" && exit 1
+
+ for dir in ${basedir}/* ; do
+ for file in ${dir}/*; do
+ if diff $file ${cin} >/dev/null 2>&1; then
+ echo -en "${fgd}`basename ${dir}`${nofg}/"
+ echo -e "${fgh}`basename ${file}`${nofg}"
+ found=1
+ fi
+ done
+ done
+ test ${found} -eq 0 && echo ${cin} is different from stored configs
+}
+
+# No arguments? give usage
+test $# -eq 0 && list && exit 0
+
+# Create $basedir if it does not exists
+test ! -d ${basedir} && mkdir -p ${basedir}
+
+# Set the default file names
+cin=config.h
+list=0
+
+# standardize colors for shell output
+fgd="\e[${color_dirs}m"
+fgh="\e[${color_conf}m"
+nofg="\e[0m"
+
+# change colors, for fun!
+LS_COLORS="di=${color_dirs}:*.h=${color_conf}"
+export LS_COLORS
+
+# Parse options
+while getopts "chi:ld:s:r:u" opt; do
+ case $opt in
+ # Check which config is in use
+ c) check;;
+
+ # Wipe the config given as argument
+ d) rm ${basedir}/$OPTARG;;
+
+ # Change the input file
+ i) cin=$OPTARG;;
+
+ # List currently managed config.h
+ l) list=1; break;;
+
+ # Whether to store or restore a config.h
+ s) store $OPTARG;;
+ r) restore $OPTARG;;
+
+ # WHAAT?!
+ h) usage full; exit 0;;
+ *) usage; exit 1;;
+ esac
+done
+
+# In case we want to list files managed...
+shift $(( OPTIND - 1 ))
+
+# List either the whole dir or a specific one
+test $list -eq 1 && list $1
(DIR) diff --git a/hmgr b/hmgr
t@@ -1,136 +0,0 @@
-#!/bin/sh
-#
-# z3bra - (c) wtfpl 2014
-# Manage your config.h files on a per program basis. Store defaults and user
-# configs, and restore them easily.
-
-# Directory where configs are saved
-basedir=~/.hmgr.d
-
-# Default names for configs
-default=config.def.h
-
-# How to list files managed by hmgr
-#listcmd='ls -1 --color=auto'
-listcmd='tree -L 1 --noreport'
-
-# Change output colors ?
-color_conf='1;37' # colors for config files
-color_dirs='0;33' # colors for directory names
-
-
-usage() {
-echo "usage: $(basename $0) [-hu] [-l [dir]] [-din <file>] [-csr <dir>]"
-
-test -z "$1" && return
-
-cat <<EOF
- -h : help
- -u : shortcut for -n ${USER}.h
-
- -l [dir] : list currently managed applications/files
-
- -d <dir>/<name> : remove <name> from managed configs
- -i <file> : input file to use (defaults to ./config.h)
- -n <name> : deal with file as <name> (defaults to config.def.h)
-
- -c <dir> : check which config is in use
- -s <dir> : store \`config.h\` to <dir>
- -r <dir> : restore \`config.h\` from <dir>
-EOF
-}
-
-store() {
- test -z "$1" && return 1
- test ! -d ${basedir}/$1 && mkdir ${basedir}/$1
-
- # Copy from current dir to base directory
- cp -i ${cin} ${basedir}/$1/${cout}
-}
-
-restore() {
- test -z "$1" && return 1
-
- # Copy from base dir to current directory
- cp ${basedir}/$1/${cout} ${cin}
-}
-
-list() {
-
- # Go to the base directory
- cd ${basedir}
-
- ${listcmd} $1
-}
-
-check() {
- found=0
-
- test ! -f ${cin} && echo "cannot find file ${cin}" && exit 1
-
- for dir in ${basedir}/*; do
- for file in ${dir}/*; do
- if diff $file ${cin} >/dev/null; then
- echo -en "${fgd}`basename ${dir}`${nofg}: "
- echo -e "${fgh}`basename ${file}`${nofg}"
- found=1
- fi
- done
- done
- test ${found} -eq 0 && echo ${cin} is different from stored configs
-}
-
-# No arguments? give usage
-test $# -eq 0 && list && exit 0
-
-# Create $basedir if it does not exists
-test ! -d ${basedir} && mkdir ${basedir}
-
-# Set the default file names
-cin=config.h
-cout=${default}
-list=0
-
-# standardize colors for shell output
-fgd="\e[${color_dirs}m"
-fgh="\e[${color_conf}m"
-nofg="\e[0m"
-
-# change colors, for fun!
-LS_COLORS="di=${color_dirs}:*.h=${color_conf}"
-export LS_COLORS
-
-# Parse options
-while getopts "chi:ld:n:s:r:u" opt; do
- case $opt in
- # Check which config is in use
- c) check;;
-
- # Wether to use default config or user config
- u) cout=${usercfg};;
- n) cout=${OPTARG};;
-
- # Wipe the config given as argument
- d) rm ${basedir}/$OPTARG;;
-
- # Change the input file
- i) cin=$OPTARG;;
-
- # List currently managed config.h
- l) list=1; break;;
-
- # Whether to store or restore a config.h
- s) store $OPTARG;;
- r) restore $OPTARG;;
-
- # WHAAT?!
- h) usage full; exit 0;;
- *) usage; exit 1;;
- esac
-done
-
-# In case we want to list files managed...
-shift $(( OPTIND - 1 ))
-
-# List either the whole dir or a specific one
-test $list -eq 1 && list $1
(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/info.sh b/info.sh
t@@ -30,7 +30,7 @@ system=`sed 's/\s*[\(\\]\+.*$//' /etc/issue`
if [ -n "$DISPLAY" ]; then
wmname=`xprop -root WM_NAME|cut -d\" -f2`
- termfn=`sed -n 's/^.*\*font:\s* -\*-\([^-]*\)-.*/\1/p' ~/.Xresources`
+ termfn=`sed -n 's/^.*\*font:\s* -\*-\([^-]*\)-.*/\1/p' ~/.Xresources|sed 1q`
systfn=`sed -n 's/^.*font.*"\(.*\)".*$/\1/p' ~/.gtkrc-2.0`
else
wmname="none"
(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@@ -23,12 +23,13 @@ alsactl=Master # which alsa channel to display
battery=$(ls /sys/class/power_supply | grep BAT)
barch=''
-barfg='%{F#ffffffff}'
-barbg='%{F#00333333}'
+barfg='%{F#ff666666}'
+barmg='%{F#ff2288cc}'
+barbg='%{F#00888888}'
-grpfg='%{F#fffff000} '
-grpmg='%{F#ff666666} '
-grpbg='%{F#00ffffff} '
+grpfg='%{F#ff111111} '
+grpmg='%{F#ff2288cc} '
+grpbg='%{F#ffbbbbbb} '
# no need to modify anything else here
t@@ -119,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
}
t@@ -177,34 +178,34 @@ makebar() {
buf="%{l} "
# Set icon depending on the interface that is up
-buf="${buf}%{F#ff49d4dd} "
+buf="${buf}${barmg} "
if test "$(netint)" = "eth0"; then
- buf="${buf}%{F-}"
+ buf="${buf}${barfg}"
elif test "$(netint)" = "wlan0"; then
- buf="${buf}%{F-}"
+ buf="${buf}${barfg}"
else
- buf="${buf}%{F-}"
+ buf="${buf}${barfg}"
fi
buf="$buf $(netstate) "
-buf="${buf}%{F#ffcef318} %{F-} $(nettrafic down) "
-buf="${buf}%{F#ffd43f10} %{F-} $(nettrafic up) "
+buf="${buf}${barmg} ${barfg} $(nettrafic down) "
+buf="${buf}${barmg} ${barfg} $(nettrafic up) "
buf="${buf}%{c} $(gstate)"
buf="${buf}%{r}"
-buf="${buf}%{F#ffede265} %{F-} $(mails) "
+buf="${buf}${barmg} ${barfg} $(mails) "
# Change icon if volume is muted
if amixer get $alsactl | grep '\[off\]' >/dev/null; then
- buf="${buf}%{F#ffd43f10} %{F-} "
+ buf="${buf}${barmg} ${barfg} "
else
- buf="${buf}%{F#ff6ac0fd} %{F-} "
+ buf="${buf}${barmg} ${barfg} "
fi
buf="${buf}$(makebar $(volume)) "
# Show battery status if there is a battery (U DONT SAY)
test -n "${battery}" &&
- buf="${buf}%{F#ffef79ae} %{F-} $(makebar $(battery)) "
+ buf="${buf}${barmg} ${barfg} $(makebar $(battery)) "
-buf="${buf}%{F#ffb3b3b3} %{F-} $(clock) "
+buf="${buf}${barmg} ${barfg} $(clock) "
echo $buf
sleep ${refresh_rate}
(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="#00000000"
+bg="#ff333333"
fg="#ffffffff"
-hl="#ff333333"
+hl="#ff6ac0fd"
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/prtmk b/prtmk
t@@ -1,8 +1,11 @@
#!/bin/sh
+#
+# z3bra - (c) wtfpl 2014
+# Create a Pkgfile from simple templates and user input
PKGFILE=~/src/ports/Pkgfile
PORTDIR=~/usr/ports
-test -z $EDITOR && EDITOR=vim
+EDITOR=${EDITOR:vim}
echo_color () {
tput bold
t@@ -20,9 +23,6 @@ read -p 'URL : ' url
read -p 'Source : ' sources
read -p 'Depends on : ' depends
-source=${source//$name/\$name}
-source=${source/$version/\$version}
-
PORTDIR=$PORTDIR/$name
if test "$version" = "git"; then
t@@ -31,6 +31,9 @@ if test "$version" = "git"; then
PKGFILE=${PKGFILE}-git
PORTDIR=${PORTDIR}-git
+else
+ sources=${sources//$name/\$name}
+ sources=${sources/$version/\$version}
fi
echo -n "creating port $name .. "
(DIR) diff --git a/prtup b/prtup
t@@ -0,0 +1,70 @@
+#!/bin/sh
+#
+# z3bra - (c) wtfpl 2014
+# Update git hashes in a Pkgfile
+
+PKGMK_ARCH=64 source /etc/pkgmk.conf
+
+echo_color () {
+ tput bold
+ tput setaf $1
+ shift
+
+ echo "$@"
+
+ tput sgr0
+}
+
+# check wether we're in a port directory or not
+if [ ! -f Pkgfile ]; then
+ echo_color 1 "Not in a port directory"
+ exit 1
+fi
+
+port_dir=$PWD
+
+get_version() {
+ cd $PKGMK_SOURCE_DIR
+
+ # enter the git directory
+ if cd $name; then
+
+ # get the git hash and its minimized version
+ version=$(git log --oneline --format="git-%h" | sed 1q)
+ sversion=$(git log --oneline --format="%H" | sed 1q)
+ else
+ echo_color 1 'Cannot check git sources'
+ exit 1
+ fi
+}
+
+update_pkgfile() {
+ cd $port_dir
+
+ # update version
+ sed -i "s/^version=.*$/version=$version/" Pkgfile
+
+ # update sversion if it exists
+ if grep 'sversion' Pkgfile; then
+ sed -i "s/^sversion=.*$/sversion=$sversion/" Pkgfile
+
+ # create it otherwise
+ else
+ sed -i "/version/a\
+ sversion=$sversion" Pkgfile
+ fi
+}
+
+main() {
+
+ # we'll need the $name var later
+ source Pkgfile
+
+ # get the git hashes
+ get_version
+
+ # update Pkgfile accordingly
+ update_pkgfile
+}
+
+main
(DIR) diff --git a/translate b/translate
t@@ -16,7 +16,7 @@ TEXT=$1
SL=$(test -n "$SL" && echo "$SL" || echo auto)
TL=$(test -n "$TL" && echo "$TL" || echo en)
-TRANSLATEURL='http://translate.google.com/'
+TRANSLATEURL='https://translate.google.com/'
UA='Mozilla 5.0'
NEWLINE='\
'
(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