-
Notifications
You must be signed in to change notification settings - Fork 0
/
smartzip
executable file
·69 lines (65 loc) · 1.36 KB
/
smartzip
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/bin/bash
source "$HOME/CodeHub/SHELL/libs/bootstrap.sh"
HELP_MESSAGE="
desc:
智能地解压文件,支持 *.zip, *.tar.gz, *.bz2, *.7z
usage:
smartzip FILE [DIRECTORY]
examples:
website wordpress.zip
website wordpress.zip /www/
"
if [[ -z "$1" || "$1" = "--help" || "$1" = "-h" ]]; then
helpShow
fi
# cmd 命令操作方式
case "$1" in
--help)
helpShow;;
esac
ftype=`file "$1"`
case "$ftype" in
"$1: RAR archive"*)
if [[ -z "$2" ]]; then
unrar x "$1"
else
unrar x "$1" "$2"
fi
;;
"$1: Zip archive"*)
if [[ -z "$2" ]]; then
unzip "$1"
else
unzip "$1" -d "$2"
fi
;;
"$1: XZ compressed"*)
if [[ -z "$2" ]]; then
tar -xvf "$1"
else
tar -xvf "$1" -C "$2"
fi
;;
"$1: gzip compressed"*)
if [[ -z "$2" ]]; then
tar -zxvf "$1"
else
tar -zxvf "$1" -C "$2"
fi
;;
"$1: bzip2 compressed"*)
if [[ -z "$2" ]]; then
tar -jxvf "$1"
else
tar -jxvf "$1" -C "$2"
fi
;;
"$1: 7-zip archive"*)
if [[ -z "$2" ]]; then
7z x "$1"
else
7z x -o"$2" "$1"
fi
;;
*) echo "File $1 can not be uncompressed with smartzip";;
esac