Archive for December, 2008

Pmv: mv with progress bar

Friday, December 26th, 2008

Bash script which display a progress bar dugin a mv operation.

#!/usr/bin/env bash

[ $# != 2 ] && printf "usage: $0  n" && exit 1
trap 'rm -rf $2' 1 2 15 # HUP INT TERM

width=$(tput cols)
length=$(($width -6))
i=1; eq=''; ws=''
while [ $i -lt $length ]; do
        eq="$eq="
        ws="$ws "
        i=$(($i + 1))
done
cur=0; tot=$(stat -c %s $1 2>/dev/null)
(mv $1 $2) &
[ -z $tot ] && wait && exit 1
while [ $cur -le $tot ]; do
        i=$(( $cur*$length/$tot ))
        percentage=$(( $cur*100/$tot ))
        printf "r[${eq:0:$i}${ws:$i}] %3d%%" $percentage
        [ $cur -eq $tot ] && break
        sleep 0.1
        cur=$(stat -c %s $2 2>/dev/null)
        [ -z $cur ] && cur=0
done
printf "n"

Save it inside ~/bin, or /usr/bin.
Make it executable.
Enjoy.

Autoscatto support poetry, please support Autoscatto.

Tuesday, December 9th, 2008

Nothing but a small example of what “Obfuscated C” means:

char o,k,h[0x18],s[]={'x54','x48','x49','x53','x20','x49',
'x53',32,'x41',040,'x53','x51','x55','x41','x52','x45' ,
'x00' }; void space(int i){ i=i%5; i=(i==0)?42:i==1?43:i==2?35:
i==3?64:i==4?94:126 ; k=0; while(k!='O'-'2'){putchar(i);  k++;} }
void m(int l, int b,...){int i=b&&putchar(10)&&(1==0);putchar(9);
for(;(i<=l);i++){ putchar((b)?*(s+i):*(s+l-i)); putchar(*(s+7));}
putchar(10);} main(){char $[]={99,0,0,*(s+0x0D)+040,1?'r':(1),0};
*($+2)=*($+1)=*$+9,o=0; *($+2)-=7;int j,i=(1==2);for(j=0;j<'6'/2;
j++){*(h+j)=040;}int l= 0x0F;k=1;for(;;){o++;i=0;system($);for(;
i<l;i++){(i==0)?(m(l,1)):(putchar(9), putchar(*(s+i)),space(o+1),
putchar(*(s+l-i)),putchar(10) );}m(l,0);usleep(('}'-'2')*1000);}}
/* {}  Autoscatto support poetry, please support Autoscatto {} */

It has not been written by me, I'm just supporting Autoscatto.

Compile it with:

gcc -o [] [].c