scripts

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

commit 97fe62e7733bd37d296a724f2af10b12a82cd5a0
parent 70d26e048e165bc4954ea89a4c7d2338a7750ac9
Author: z3bra <willy@mailoo.org>
Date:   Thu Nov  6 14:53:38 +0100

Merge branch 'master' of z3bra.org:scripts

Diffstat:
bar/config.sh | 72------------------------------------------------------------------------
bar/status.sh | 227-------------------------------------------------------------------------------
cdump | 4++--
cpu | 28++++++++++++++++++++++++++++
cpuload | 22----------------------
human | 67-------------------------------------------------------------------
sloc | 5+++++
square | 4++--
syscat | 39+++++++++++++++++++++++++++++++++++++++
xgif | 45+++++++++++++++++++++++++++++++++++++++++++++
10 files changed, 121 insertions(+), 392 deletions(-)
diff --git a/bar/config.sh b/bar/config.sh @@ -1,72 +0,0 @@ -#!/bin/bash - -# Color used in the bar (extracted from .Xresources) -# * 0 : black -# * 1 : red -# * 2 : green -# * 3 : yellow -# * 4 : blue -# * 5 : magenta -# * 6 : cyan -# * 7 : white - -# unified colors -bg="8" -fg="9" -hl="8" - -# separator -sp=" " - -# path to executable -bar="/usr/bin/bar -f" - -#info icons (from stlarch_font package. use gbdfed to view/modify font) -i_arch='\ue0a1' # arch logo -i_pkgs='\ue14d' # pacman -i_pkgs='\ue0aa' # pacman ghost -i_mail='\ue072' # mail icon -i_wifi='\ue0f0' # signal -i_netw='\ue149' # wired -i_time='\ue017' # clock -i_batt='\ue040' # thunder -i_sect='\ue10c' # power (on A/C) -i_load='\ue021' # micro chip -i_memy='\ue145' # floppy -i_musk='\ue04d' # headphones -i_alsa='\ue05d' # speaker - -# workspace icons / names (α β γ δ ε ζ η θ ι κ λ) -i_trm=$(echo -e '0') -i_web=$(echo -e '1') -i_dev=$(echo -e '2') -i_com=$(echo -e '3') -i_fun=$(echo -e '4') -i_sys=$(echo -e '5') -i_wrk=$(echo -e '6') -i_meh=$(echo -e '7') -i_far=$(echo -e '8') - - -# specific parameters -# desktop names -dskp_tag=('' $i_trm $i_web $i_dev $i_com $i_fun $i_sys $i_wrk $i_meh $i_far) - -# colors -colors=(black red green yellow blue cyan magenta white black white) - -# now playing format -mpc_format='[%title% ]|[%file%]' - -# volume channel -alsa_channel='Master' - -# define you own interfaces -net_wire='eth0' -net_wifi='wlan0' - -# Only the time ? with seconds ? Maybe the current year...? -date_format="%H.%M" - -# The default program to use, is -O <program> is not passed -default_output='bar' diff --git a/bar/status.sh b/bar/status.sh @@ -1,227 +0,0 @@ -#!/bin/sh - -source $(dirname $0)/config.sh - -OUT=$default_output - -function fg() { - case $1 in - bar) echo "\f$2" ;; - tmux) echo "#[fg=${colors[$2]}]" ;; - none) echo "" ;; - ?) echo "\f$2" ;; - esac -} - -function bg() { - case $1 in - bar) echo "\b$2" ;; - tmux) echo "#[bg=$2]" ;; - none) echo "" ;; - ?) echo "\b$2" ;; - esac -} - -# print formatted output. need 2 params: display <value> <icon> -function display () { - if [ -n "$1" ]; then - echo -n "$(fg $OUT ${hl})" - echo -en "$2 " - echo "$(fg $OUT ${fg})$1" - fi -} - -function workspaces () { - dskp_num=$(xprop -root _NET_NUMBER_OF_DESKTOPS | cut -d ' ' -f3) - dskp_cur=$(xprop -root _NET_CURRENT_DESKTOP | cut -d ' ' -f3) - - buffer="" - - for w in $(seq 1 $(($dskp_num-1))); do - if [ "$w" -eq "$dskp_cur" ]; then - buffer="$buffer$(echo -e '\ue190')" - #buffer="$buffer\u${fg} ${dskp_tag[$w]} \u${bg}" - else - buffer="$buffer$(fg $OUT ${hl})$(echo -e '\ue190')$(fg $OUT ${fg})" - #buffer="$buffer ${dskp_tag[$w]} " - fi - done - - echo -n "${buffer}" -} - -function ratgrp() { - dskp_tag=('' 'MEH' 'WEB' 'DEV') - dskp_cur=$(ratpoison -c 'groups' | cut -sd'*' -f1) - dskp_num=$(ratpoison -c 'groups'| wc -l) - - val="" - - for w in $(seq 1 $dskp_num); do - if [ "$w" -eq "$dskp_cur" ]; then - val="$val\u${fg} ${dskp_tag[$w]} \u${bg}" - else - val="$val ${dskp_tag[$w]} " - fi - done - - echo -n "${val}" -} - -function groups() { - if [ "$(xprop -root _NET_WM_NAME|cut -d\" -f2)" = "ratpoison" ]; then - echo "$(ratgrp)" - else - echo "$(workspaces)" - fi -} - -function mails () { - new=$(~/bin/mcount ~/var/mail/INBOX/new/) - #cur=$(~/bin/mcount ~/var/mail/INBOX/cur/) - #val="$new/$cur" - val="$new" - ico=${i_mail} - - display "$val" "$ico" -} - -function mpd_now_playing () { - val=$(mpc current --format "$mpc_format" 2>/dev/null) - ico=${i_musk} - - if [[ -z $val ]]; then - val='' - ico='' - fi - - display "$val" "$ico" -} - -function volume () { - val=$(amixer sget $alsa_channel | sed -n 's/.*\[\([0-9/]*%\)\].*/\1/p' | uniq) - ico=${i_alsa} - - display "$val" "$ico" -} - -function battery () { - val=$(acpi -b | sed 's/^.* \([0-9]*%\).*$/\1/') - ico=${i_batt} - - display "$val" "$ico" -} - -function packages () { - - val=$"$(pacman -Q| wc -l) pkg" - ico=${i_pkgs} - - display "$val" "$ico" -} - -function memory () { - - mem_tot=$(free -m| sed -n 2p| awk '{print $2}') - mem_use=$(free -m| sed -n 3p| awk '{print $3}') - val="$(echo "$mem_use*100/$mem_tot" | bc)%" - ico=${i_memy} - - display "$val" "$ico" -} - -function gputemp () { - - val="$(nvidia-smi -q -d TEMPERATURE | grep Gpu | sed 's/.*: //')" - ico=${i_grap} - - display "$val" "$ico" -} - -function gpufanspeed () { - - val="$(nvidia-smi -q | grep "Fan" | sed 's/.*: \([0-9]*\).*$/\1/')%" - ico=${i_fans} - - display "$val" "$ico" -} - -function processes () { - - val="$(iostat -c | sed -n "4p" | awk -F " " '{print $1}')%" - ico=${i_load} - - display "$val" "$ico" -} - -function network () { - - interface_up=$(ip link | grep 'state UP' | wc -l) - - if [ ${interface_up} -gt 1 ]; then - val="multi connection" - ico=${i_netw} - else - - net_interface=$(ip link| grep 'state UP'| - sed 's/[0-9]: \([^:]*\):.*$/\1/') - if [ "$net_interface" = "$net_wire" ]; then - val=$(ip addr show $net_interface| grep 'inet '| - sed 's#.* \(.*\)/.*$#\1#') - ico=${i_netw} - elif [ "$net_interface" = "$net_wifi" ]; then - val=$(ip addr show $net_interface| grep 'inet '| - sed 's#.* \(.*\)/.*$#\1#') - ico=${i_wifi} - else - val="" - ico=${i_netw} - fi - fi - - [[ -z "$val" ]] && val="disconnected" - - display "$val" "$ico" -} - -function clock () { - val=$(date +${date_format}) - ico=${i_time} - - display "$val" "$ico" -} - -function fillbar () { - while getopts "B:F:H:LCRO:s:bcflmnprtvw" opt; do - case $opt in - # Specific options for bar-aint-recursive - B) bg=$OPTARG ;; # background color - F) fg=$OPTARG ;; # foreground color - H) hl=$OPTARG ;; # highlights color - L) buffer="${buffer}\l " ;; # left justify - C) buffer="${buffer}\c " ;; # center text - R) buffer="${buffer}\r " ;; # right justify - - # Which program is the output intended for ? (bar|tmux|none) - O) OUT=$OPTARG ;; - - # Content of the output - b) [[ -n "$(battery)" ]] && buffer="${buffer}$(battery) ${sp}" ;; - c) [[ -n "$(clock)" ]] && buffer="${buffer}$(clock) ${sp}" ;; - f) [[ -n "$(gpufanspeed)" ]] && buffer="${buffer}$(gpufanspeed) ${sp}" ;; - l) [[ -n "$(mpd_now_playing)" ]] && buffer="${buffer}$(mpd_now_playing) ${sp}" ;; - m) [[ -n "$(mails)" ]] && buffer="${buffer}$(mails) ${sp}" ;; - n) [[ -n "$(network)" ]] && buffer="${buffer}$(network) ${sp}" ;; - p) [[ -n "$(processes)" ]] && buffer="${buffer}$(processes) ${sp}" ;; - r) [[ -n "$(memory)" ]] && buffer="${buffer}$(memory) ${sp}" ;; - t) [[ -n "$(gputemp)" ]] && buffer="${buffer}$(gputemp) ${sp}" ;; - v) [[ -n "$(volume)" ]] && buffer="${buffer}$(volume) ${sp}" ;; - w) [[ -n "$(groups)" ]] && buffer="${buffer}$(groups) ${sp}" ;; - esac - done - - # Set the default fg/bg and remove trailing separator (if any) - echo "$(bg $OUT ${bg})$(fg $OUT ${fg}) $buffer " | sed "s/${sp}$//" -} - -fillbar $@ diff --git a/cdump b/cdump @@ -9,11 +9,11 @@ for NUM in $(seq 0 7); do done echo for NUM in $(seq 0 7); do - printf "\e[0;3${NUM}m||||||| " + printf "\e[0;3${NUM}m▒▒▒▒▒▒▒ " done echo for NUM in $(seq 0 7); do - printf "\e[1;3${NUM}m||||||| " + printf "\e[1;3${NUM}m▒▒▒▒▒▒▒ " done echo for NUM in $(seq 0 7); do diff --git a/cpu b/cpu @@ -0,0 +1,28 @@ +#!/bin/sh +# +# z3bra - (c) wtfpl 2014 + +usage () { + cat <<EOF +usage: $(basename $0) [-hp] + -h : print help + -p : percentage of cpu used (default) + -n : number of running processes +EOF +} + +cpuperc () { + LINE=`ps -eo pcpu |grep -vE '^\s*(0.0|%CPU)' |sed -n '1h;$!H;$g;s/\n/ +/gp'` + + echo "`echo $LINE | bc`%" +} + +cpunumb() { + ls /proc | grep -oE '^[0-9]*$' | wc -w +} + +case $1 in + -h) usage;; + -n) cpunumb;; + *) cpuperc;; +esac diff --git a/cpuload b/cpuload @@ -1,22 +0,0 @@ -#!/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 "`echo $LINE | bc`%" -} - -case $1 in - -h) usage;; - *) cpuperc;; -esac diff --git a/human b/human @@ -1,67 +0,0 @@ -#!/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=`echo "scale=${SCALE}; ${num} / (1024 ^ ${pow})" | bc` - - 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 diff --git a/sloc b/sloc @@ -0,0 +1,5 @@ +#!/bin/sed -f + +/^$/d +/^\s*[{}]/d +/^\s*[/*]/d diff --git a/square b/square @@ -1,5 +1,5 @@ #!/bin/sh echo -for i in {0..7}; do echo -en " \e[0;3${i}m▉▉▉▉\e[0m"; done; echo -for i in {0..7}; do echo -en " \e[1;3${i}m▉▉▉▉\e[0m"; done; echo +for i in {0..7}; do echo -en " \e[0;3${i}m▒▒\e[0m"; done; echo +for i in {0..7}; do echo -en " \e[1;3${i}m▒▒\e[0m"; done; echo diff --git a/syscat b/syscat @@ -0,0 +1,39 @@ +#!/bin/sh + +COLOR=${COLOR:-15} + +c() { tput setaf $COLOR; } +d() { tput sgr0; } + +gitdir=http://git.z3bra.org +myblog=http://blog.z3bra.org + +system() { + sed "/^$/d;s/\s*[\(\\]\+.*$//" /etc/issue +} + +cpuinfo() { + sed -n "/model\ name/s/^.*:\ //p" /proc/cpuinfo | sed 1q +} + +wmname() { + xprop -root WM_NAME | cut -d\" -f2 +} + +fontname() { + xrdb -query|sed "/URxvt\*font/s/^[^-]*-\*-\([^-]*\)-.*$/\1/p;d" +} + +cat <<EOF + +$(c)SYSTEM $(d)$(system) +$(c)KERNEL $(d)$(uname -r) +$(c)HOSTNAME $(d)$HOSTNAME +$(c)WMNAME $(d)$(wmname) +$(c)TERMINAL $(d)$TERM +$(c)SHELL $(d)$SHELL +$(c)FONT $(d)$(fontname) +$(c)PROC $(d)$(~/bin/cpu -p) +$(c)MEMORY $(d)$(~/bin/memory -u) + +EOF diff --git a/xgif b/xgif @@ -0,0 +1,45 @@ +#!/bin/sh +# +# z3bra - (c) wtfpl 2014 +# record a gif from a specific window until ^D + +usage () { + cat <<EOF +usage: `basename $0` [-h] <file> + -h : print this help + +environment: + BORDERS : set the window border size (default: 5) +EOF +} + +case $1 in + -h) usage && exit 0;; + *) test $# -lt 1 && usage && exit 1 +esac + +# the size of your window manager borders, to include them in the gif +BORDERS=${BORDER:-5} + +# let the user grab a window +geom=$(xwininfo|grep -E "Wid|Hei|Abs"|sed 's/.*:\s*//g'|tr '\n' :|sed 's/:$//') + +# extract window size/position +x=$(echo $geom|cut -d: -f1) +y=$(echo $geom|cut -d: -f2) +w=$(echo $geom|cut -d: -f3) +h=$(echo $geom|cut -d: -f4) + +# add the borders to the width/heigh +w=$(( $w + 2 * $BORDERS)) +h=$(( $h + 2 * $BORDERS)) + +# this hackery serves the purpose of recording until the user press ^D +fifo="/tmp/xgif-$$.fifo" +test -p $fifo || mkfifo $fifo + +byzanz-record -x $x -y $y -w $w -h $h -e "cat $fifo" $1 & + +# will hold the fifo openned until ^D is pressed +cat > $fifo +rm $fifo