Sunday, January 03, 2010

Unpack functions and BSDProgress - progress bar for your archives.

A colored unpack script using bar:

A little KSH93 function for your .profile. Now you can augomatically unpack most archives while watching the pretty progress bar.
You need bsdprogress (Solaris and Linux port of NetBSD's progress). With a bit work it also works on AIX.
I just re-wrote this for progress, so I didn't check the cpio and such yet.
# Mihai Criveti - Unpack function:
# Progress Unpack - unpack using GNU tar and bsdprogress.
function up {
for archive in $*; do
print $archive;
case $archive in
(*.tar) progress -f $archive gtar xpif - ;;
(*.tar.gz) progress -f $archive gtar -zpixf - ;;
(*.tgz) progress -zf $archive gtar -ipxf - ;;
(*.tar.bz2) progress -f $archive gtar -jipxf - ;;
(*.tbz) progress -f $archive gtar -jipxf - ;;
(*.gz) progress -f $archive gunzip -;;
(*.bz2) progress -f $archive bunzip -;;
(*.tar.Z) uncompress -c $archive | tar gxvf - ;;
(*.cpio) cpio -icd < $archive ;;
(*.Z) uncompress $archive ;;
(*.rar) unrar x $archive ;;
(*.zip) unzip $archive ;;

Let's say we want to unpack files that end in *bz2 (it will automagically detect .tar.bz2 or tbz2), *gz and a specific tar archive:

cmihai@phobos:/home/cmihai/build$ up g*bz2 c*gz Python\-3.0.1.tar
100% |**********************************************************************| 3330 KB 296.95 KB/s 00:00 ETA
100% |**********************************************************************| 3888 KB 340.20 KB/s 00:00 ETA
100% |**********************************************************************| 86363 201.51 KB/s 00:00 ETA
91% |******************************************************** | 43320 KB 787.63 KB/s 05:00 ETA

It builds fine on AIX (Makefile tweaks), Solaris and Linux. Native on NetBSD.
Other versions: