diff --git a/functions.sh b/functions.sh index a7adec2..bc95e68 100755 --- a/functions.sh +++ b/functions.sh @@ -8,49 +8,55 @@ mkcd() { mkdir $1 && cd $1 } rcd() { cd .. && rm -irfv $OLDPWD } extract () { - if [ -f $1 ] ; then - case $1 in - *.tar.bz2) tar xjf $1 ;; - *.tar.gz) tar xzf $1 ;; - *.tar.xz) tar xJf $1 ;; - *.bz2) bunzip2 $1 ;; - *.lbz2) lbunzip2 -kn$((`grep "^processor" /proc/cpuinfo | wc -l`+1)) $1 ;; - *.rar) unrar x $1 ;; - *.gz) gunzip $1 ;; - *.tar) tar xf $1 ;; - *.tbz2) tar xjf $1 ;; - *.tbz) tar -xjvf $1 ;; - *.tgz) tar xzf $1 ;; - *.txz) tar xJf $1 ;; - *.zip) unzip $1 ;; - *.Z) uncompress $1 ;; - *.7z) 7z x $1 ;; - *) echo "I don't know how to extract '$1'..." ;; - esac - else - echo "'$1' is not a valid file" - fi + if [ $2 ] ; then + echo "too many parameters to extract ()" + elif [ -f "$1" ] ; then + case $1 in + *.tar.bz2|*.tbz2|*.tbz) tar xjf $1 ;; # FIXME: make parallel with lbunzip2 + *.tar.gz|*.tgz) tar xzf $1 ;; + *.tar.xz|*.txz) tar xJf $1 ;; + *.tar) tar xf $1 ;; + *.bz2) which lbunzip2 &>/dev/null \ + && lbunzip2 -kn$((`grep "^processor" /proc/cpuinfo -c`+1)) $1 \ + || bunzip2 -c $1 > ${1%.bz2} ;; + *.gz) gunzip -c $1 > ${1%.gz} ;; + *.xz) unxz -c $1 > ${1%.xz} ;; + *.rar) unrar x $1 ;; # FIXME: test + *.zip) unzip $1 ;; + *.Z) uncompress $1 ;; # FIXME: test + *.7z) 7z x $1 ;; + *) echo "I don't know how to extract '$1'..." ;; + esac + else + echo "'$1' is not a valid file" + echo "Usage: extract file" + fi } pk () { - if [ $1 ] ; then - case $1 in - tbz) tar cjvf $2.tar.bz2 $2 ;; - tgz) tar czvf $2.tar.gz $2 ;; - tgz) tar cJvf $2.tar.xz $2 ;; - tar) tar cpvf $2.tar $2 ;; - bz2) bzip2 $2 ;; - lbz2) lbzip2 -kn$((`grep "^processor" /proc/cpuinfo | wc -l`+1)) $2 ;; - gz) gzip -c -9 -n $2 > $2.gz ;; - xz) xz -c -9 $2 > $2.xz ;; - zip) zip -r $2.zip $2 ;; - 7z) 7z a $2.7z $2 ;; - *) echo "'$1' cannot be packed via pk()" ;; - esac - else - echo "'$1' is not a valid file" - fi + if [ $3 ] ; then + echo "too many parameters to pk ()" + elif [ $1 ] ; then + case $1 in + t*b*z*) tar cjvf $2.tar.bz2 $2 ;; # FIXME: make parallel with lbzip2 + t*g*z) tar czvf $2.tar.gz $2 ;; + t*x*|t*J*) tar cJvf $2.tar.xz $2 ;; + t*r) tar cpvf $2.tar $2 ;; + b*z*) which lbzip2 &>/dev/null \ + && lbzip2 -9 -kn$((`grep "^processor" /proc/cpuinfo -c`+1)) $2 \ + || bzip2 -9 -c $2 > $2.bz2 ;; + g*z) gzip -c -9 -n $2 > $2.gz ;; + x*z) xz -c -9 $2 > $2.xz ;; + rar) ;; # FIXME: test + zip) zip -9 -r $2.zip $2 ;; + Z) ;; # FIXME: test + 7z) 7z -mx=9 a $2.7z $2 ;; + *) echo "'$1' cannot be packed via pk()" ;; + esac + else + echo "Usage: pk tbz file" + fi } calc() {