-
Notifications
You must be signed in to change notification settings - Fork 3
/
xf
executable file
·45 lines (40 loc) · 1.01 KB
/
xf
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
37
38
39
40
41
42
43
44
45
#!/bin/bash
# Extract common file formats.
# Display usage if no parameters given
if [[ -z $* ]] || echo "$*" | grep -Eq -- '--help\b|-h\b'; then
echo "usage: ${0##*/} <archive> - extract common file formats"
exit
fi
# Required program(s)
# req_progs=(7z unrar unzip)
req_progs=(unrar unzip)
for p in ${req_progs[*]}; do
hash "$p" 2>&- ||
{
echo >&2 " Required program \"$p\" not installed."
exit 1
}
done
# Test if file exists
if [ ! -f "$*" ]; then
echo "File $* doesn't exist"
exit
fi
# Extract file by using extension as reference
case "$@" in
# *.7z ) 7z x "$@" ;;
*.tar.bz2) tar xvjf "$@" ;;
*.bz2) bunzip2 "$@" ;;
*.deb) ar vx "$@" ;;
*.tar.gz) tar xvf "$@" ;;
*.gz) gunzip "$@" ;;
*.tar) tar xvf "$@" ;;
*.tbz2) tar xvjf "$@" ;;
*.tar.xz) tar xvf "$@" ;;
*.tgz) tar xvzf "$@" ;;
*.rar) unrar x "$@" ;;
# *.rar ) 7z x "$@" ;;
*.zip) unzip "$@" ;;
*.Z) uncompress "$@" ;;
*) echo " Unsupported file format" ;;
esac