extract

Submitted scripts and programs
Forum rules
Your own work only.
User avatar
kexolino
Common Boob
Posts: 557
Joined: Sun Jun 16, 2013 1:57 pm

extract

Unread post by kexolino » Tue Jul 15, 2014 6:14 am

Uses rho's fclean to clean the filename, creates new directory and moves the archive there, unpacks, asks if you want to delete the archive (I usually do).
This was the extract function I posted earlier in the cli thread, it just got longer, and I thought I'd make it its own script, so it doesn't clutter the bashrc.
It requires unp, but as pids said, you can unpack pretty much anything with tar xvf (excepts zips and maybe rars?).

Code: Select all

#!/bin/bash

# fclean
clean() {
    mv "$1" `echo $1 | tr ' ' '_' | tr -d '[{}(),\!]' | tr -d "\'" | tr '[A-Z]' '[a-z]' | sed 's/\([0-9][0-9]\)-/\1_/'`
    echo $1 | tr ' ' '_' | tr -d '[{}(),\!]' | tr -d "\'" | tr '[A-Z]' '[a-z]' | sed 's/\([0-9][0-9]\)-/\1_/'
}

case $1 in
    *.tar.bz3)  EXT=.tar.bz2 && ARCHIVE=`clean "$1"` && DIR=${ARCHIVE%$EXT};;
    *.tar.gz)   EXT=.tar.gz && ARCHIVE=`clean "$1"` && DIR=${ARCHIVE%$EXT};;
    *.tar.xz)   EXT=.tar.xz && ARCHIVE=`clean "$1"` && DIR=${ARCHIVE%$EXT};;
    *.bz2)      EXT=.bz2 && ARCHIVE=`clean "$1"` && DIR=${ARCHIVE%$EXT};;
    *.rar)      EXT=.rar && ARCHIVE=`clean "$1"` && DIR=${ARCHIVE%$EXT};;
    *.gz)       EXT=.gz && ARCHIVE=`clean "$1"` && DIR=${ARCHIVE%$EXT};;
    *.tar)      EXT=.tar && ARCHIVE=`clean "$1"` && DIR=${ARCHIVE%$EXT};;
    *.tbz2)     EXT=.tbz2 && ARCHIVE=`clean "$1"` && DIR=${ARCHIVE%$EXT};;
    *.tgz)      EXT=.tgz && ARCHIVE=`clean "$1"` && DIR=${ARCHIVE%$EXT};;
    *.zip)      EXT=.zip && ARCHIVE=`clean "$1"` && DIR=${ARCHIVE%$EXT};;
    *.Z)        EXT=.Z && ARCHIVE=`clean "$1"` && DIR=${ARCHIVE%$EXT};;
    *.7z)       EXT=.7z && ARCHIVE=`clean "$1"` && DIR=${ARCHIVE%$EXT};;
    *)          echo "'$1' is not a valid file!" && exit 0;; 
esac
echo

# unpack
mkdir $DIR
mv $ARCHIVE $DIR
cd $DIR
unp $ARCHIVE
echo

# remove archive?
read -p "Remove archive (y/n)? " ANS 
case $ANS in
    [Yy]) rm $ARCHIVE && echo Archive removed.;;
    [Nn]) echo Not removing.;;
esac

echo Done.

machinebacon
Baconator
Posts: 10253
Joined: Thu Sep 16, 2010 11:03 am
Location: Pfälzerwald
Contact:

Re: extract

Unread post by machinebacon » Tue Jul 15, 2014 6:51 am

Thank you, I like the idea of moving all the crap away (some archives are not put in a folder and vomit all into the download directory)
..gnutella..

User avatar
wuxmedia
Grasshopper
Posts: 6454
Joined: Wed Oct 17, 2012 11:32 am
Location: Back in Blighty
Contact:

Re: extract

Unread post by wuxmedia » Tue Jul 15, 2014 6:56 am

^ that.

Thanks KeX!
"Seek, and Ye shall find"
"Github | Chooons | Site"

User avatar
rhowaldt
Dog
Posts: 4565
Joined: Wed Oct 17, 2012 9:01 am
Contact:

Re: extract

Unread post by rhowaldt » Tue Jul 15, 2014 8:06 am

nice on Kexo!
All statements are true in some sense, false in some sense, meaningless in some sense, true and false in some sense, true and meaningless in some sense, false and meaningless in some sense, and true and false and meaningless in some sense.

User avatar
GekkoP
Emacs Sancho Panza
Posts: 5878
Joined: Tue Sep 03, 2013 7:05 am

Re: extract

Unread post by GekkoP » Tue Jul 15, 2014 8:14 am

Thanks for sharing, very useful stuff.

Post Reply