scripts

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

commit 749f785cb103b0f0a81fd9b34643444e1e1f3901
parent 2214a036f039481f0a15bda1dcb1c3ec95d4947f
Author: z3bra <willy@mailoo.org>
Date:   Thu Jul 10 12:42:14 +0200

POSIXified the scripts

Diffstat:
backup | 43-------------------------------------------
cdump | 20++++++++++----------
chan | 16+++++++++++-----
cpuload | 3++-
deptree.sh | 47-----------------------------------------------
gamma | 4++--
hm | 4++--
human | 6+++---
imgurup | 2+-
instagram | 2+-
memory | 2+-
mkbar | 2+-
12 files changed, 34 insertions(+), 117 deletions(-)
diff --git a/backup b/backup @@ -1,43 +0,0 @@ -#!/bin/bash - -## -## Backup the content of a directory in an other directory -# - -usage() { - cat << EOF_HELP - usage : $0 <source> [<destination>] - - DESCRIPTION : - Backup <source> in /backup/<destination>. - - OUTPUT : - The backup will be an archive named : - <source>-<username>-<date>.tar.gz - - PARAMETERS : - <source> : What you want to backup - <destination> : (optional) use another directory than /backup/<username> - --help : Display this help -EOF_HELP -} - -if [[ $# -lt 1 || "$1" == "--help" || "$1" == "-h" ]]; then - usage - exit 0 -fi - -DIR=$1 -DEST=/backup -# NAME=$(echo $DIR | sed 's/\/$//' | sed 's/.*\///') -NAME=$(echo $DIR | sed 's#.*/\([^?./]*\)/$#\1#') - -if [ -n "$2" ]; then - DEST=$DEST/$2 -else - DEST=$DEST/$USER -fi - -# Create a compressed archive with the same permission that the original directory -# untar with `tar xzf <archive>.tar.gz` -tar cpzf $DEST/$USER-$NAME-$(date +%y-%m-%d).tar.gz $DIR diff --git a/cdump b/cdump @@ -3,21 +3,21 @@ FILE=$HOME/etc/Xresources FILE=$HOME/etc/theme/bow -for NUM in {0..7}; do +for NUM in $(seq 0 7); do CN=$(grep "^\*color${NUM}:" $FILE | cut -d':' -f2 | tr -d ' ') - echo -en "\e[0;3${NUM}m$CN\e[m " + printf "\e[0;3${NUM}m%s " $CN done echo -for NUM in {0..7}; do - echo -en "\e[0;3${NUM}m▉▉▉▉▉▉▉\e[m " +for NUM in $(seq 0 7); do + printf "\e[0;3${NUM}m||||||| " done echo -for NUM in {0..7}; do - echo -en "\e[1;3${NUM}m▉▉▉▉▉▉▉\e[m " +for NUM in $(seq 0 7); do + printf "\e[1;3${NUM}m||||||| " done echo -for NUM in {0..7}; do - CN=$(grep "^\*color$((${NUM}+8)):" $FILE| cut -d':' -f2 | tr -d ' ') - echo -en "\e[1;3${NUM}m$CN\e[m " +for NUM in $(seq 0 7); do + CN=$(grep "^\*color${NUM}:" $FILE | cut -d':' -f2 | tr -d ' ') + printf "\e[1;3${NUM}m%s " $CN done -echo +printf "\e[0m\n" diff --git a/chan b/chan @@ -1,4 +1,4 @@ -#!/usr/bin/bash +#!/bin/sh ## ii directory ROOT=~/var/irc @@ -15,8 +15,8 @@ usage() { EOF } -[[ -n "$1" ]] && CHAN=$1 -[[ -n "$2" ]] && NICK=$2 +test -n "$1" && CHAN=$1 +test -n "$2" && NICK=$2 while getopts ":hn:c:s:" opt; do case $opt in @@ -35,12 +35,18 @@ JOIN="/j $CHAN hai $CHAN!" # spawn ii ii -i $ROOT -n $NICK -s $SERV -p $PORT & -while [ ! -p $ROOT/$SERV/in ];do echo awaiting connection to $SERV...; sleep 2; done +while [ ! -p $ROOT/$SERV/in ]; do + echo awaiting connection to $SERV...; + sleep 2; +done # launch commands at start echo "$JOIN" > $ROOT/$SERV/in -while [ ! -p $ROOT/$SERV/$CHAN/in ];do echo Starting chatting with $CHAN; sleep 1; done +while [ ! -p $ROOT/$SERV/$CHAN/in ]; do + echo Starting chatting with $CHAN; + sleep 1; +done cd $ROOT/$SERV/$CHAN tmux new-session -d -s irc 'tail -f out' \; split-window -l 1 'ptii' \; attach diff --git a/cpuload b/cpuload @@ -12,7 +12,8 @@ EOF cpuperc () { LINE=`ps -eo pcpu |grep -vE '^\s*(0.0|%CPU)' |sed -n '1h;$!H;$g;s/\n/ +/gp'` - echo "`bc <<< $LINE`%" + + printf "%0.2f%\n" `echo $LINE | bc` } case $1 in diff --git a/deptree.sh b/deptree.sh @@ -1,47 +0,0 @@ -#!/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 b/gamma @@ -12,8 +12,8 @@ old=$gamma case $1 in get) echo $gamma; exit ;; - up) gamma=`bc <<< "$gamma + $amount"` ;; - down) gamma=`bc <<< "$gamma - $amount"` ;; + up) gamma=$( echo "$gamma + $amount" | bc) ;; + down) gamma=$( echo "$gamma - $amount" | bc) ;; reset)gamma="1.000000" ;; *) usage && exit ;; esac diff --git a/hm b/hm @@ -88,8 +88,8 @@ check() { 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}" + printf "${fgd}`basename ${dir}`${nofg}/" + printf "${fgh}`basename ${file}`${nofg}\n" found=1 fi done diff --git a/human b/human @@ -4,7 +4,7 @@ usage () { cat <<EOF -usage: $(basename $0) [-hfbmgt] <number> +usage: `basename $0` [-hfbmgt] <number> -h : print help -f : detect best factorisation to use (default) -b : force output in Bytes @@ -43,7 +43,7 @@ humanize () { *) pow=0; unit= ;; esac - num=`bc <<< "scale=${SCALE}; ${num} / (1024 ^ ${pow})"` + num=`echo "scale=${SCALE}; ${num} / (1024 ^ ${pow})" | bc` echo "${num}${unit}" } @@ -62,6 +62,6 @@ case $1 in test $# -lt 1 && usage && exit 1 - humanize $(factorize $1) $1 + humanize `factorize $1` $1 ;; esac diff --git a/imgurup b/imgurup @@ -25,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|') - tee $LOG <<< "$URL" | $CLIP + echo $URL" | tee $LOG | $CLIP echo "$DELETEURL" >> $LOG echo "$URL" done diff --git a/instagram b/instagram @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash # # 2013 z3bra <willy at mailoo dot org> # INSTAGRAM - screenshot taker / manager diff --git a/memory b/memory @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash # # z3bra - (c) wtfpl 2014 diff --git a/mkbar b/mkbar @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash # # z3bra - (c) wtfpl 2014 # Fetch infos on your computer, and print them to stdout every second.