dotfiles/bin/extract

27 lines
876 B
Plaintext
Raw Normal View History

2020-03-26 18:52:38 +00:00
#!/usr/bin/env sh
# Extracts the archive.
# The process can vary depending on the file extension.
2020-03-26 18:52:38 +00:00
# Dependencies:
# * tar (GNU tar) 1.32
# Extract each given filename.
for f in $@; do
if [ -n "$(file "$f" | grep -i '7-zip archive data')" ]; then
7z x "$f"
elif [ -n "$(file "$f" | grep -i 'zip archive data')" ]; then
unzip "$f"
elif [ -n "$(file "$f" | grep -i 'POSIX tar archive')" ]; then
tar --extract --file $f # or 'tar xf $f'
elif [ -n "$(file "$f" | grep -i 'gzip compressed data')" ]; then
tar --extract --gzip --file "$f" # or 'tar xzf $f'
elif [ -n "$(file "$f" | grep -i 'bzip2 compressed data')" ]; then
tar --extract --bzip2 --file "$f" # or 'tar xjf $f'
elif [ -n "$(file "$f" | grep -i 'RAR archive data')" ]; then
unrar x "$f"
2020-03-26 18:52:38 +00:00
else
echo "unrecognized format."
2020-03-26 18:52:38 +00:00
fi
done