forked from lzap/dancepill
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathe
executable file
·36 lines (35 loc) · 1.33 KB
/
e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/bin/bash
# :vim sw=2:ts=2:et
e() {
for F in "$@"; do
if [ -f "$F" ] ; then
FT1=$(file -bi "$F" | grep -Eo '[[:alnum:]_-]+/[[:alnum:]_-]+')
DIR="$F-e"
mkdir "$DIR" || exit 1
pushd "$DIR"
case $FT1 in
"application/x-bzip2") tar xvjf "../$F" || bunzip2 "../$F" ;;
"application/x-gzip") tar xvzf "../$F" || gunzip "../$F" ;;
"application/x-xz") tar xvJf "../$F" || xz -d "../$F" ;;
"application/x-rar") unrar x "../$F" || rar x "../$F" ;;
"application/x-arj") arj x "../$F" || 7za x "../$F" ;;
"application/x-lha") lha x "../$F" || 7za x "../$F" ;;
"application/x-cpio") cpio -i "../$F" ;;
"application/x-tar") tar xvf "../$F" || gunzip "../$F" ;;
"application/x-zip") unzip "../$F" ;;
"application/zip") unzip "../$F" ;;
"application/x-7z-compressed") 7za x "../$F" ;;
"application/x-7za-compressed") 7za x "../$F" ;;
"application/octet-stream") unlzma "../$F" || 7za x "../$F" || uncompress "../$F" ;;
*) echo "'../$F' ($FT1) cannot be extracted via e() bash function" ;;
esac
popd
# expecting only one file
if [ "$(ls "$DIR" | wc -l)" == "1" ]; then
mv -v "$DIR"/* . && rmdir "$DIR"
fi
else
echo "'$F' is not a valid file"
fi
done
}