code / scripts

Lines748 Shell528 Python72 Lua67 Bourne Again Shell62 make15
1 others 4
Markdown4
(16 lines)
1 #!/bin/sh
2 # One stop shop for file compression in various formats
3 [ $# -lt 2 ] && echo "Usage: compress <output> <files...>" && exit 1
4 out="$1"; shift
5 case "$out" in
6 *.tar.gz|*.tgz) tar czf "$out" "$@";;
7 *.tar.xz|*.txz) tar cJf "$out" "$@";;
8 *.tar.bz2) tar cjf "$out" "$@";;
9 *.tar) tar cf "$out" "$@";;
10 *.zip) zip -r "$out" "$@";;
11 *.7z) 7z a "$out" "$@";;
12 *.gz) gzip -c "$1" > "$out";;
13 *.xz) xz -c "$1" > "$out";;
14 *.bz2) bzip2 -c "$1" > "$out";;
15 *) printf "Unknown format: \033[31;1m%s\033[0m\n" "$out"; exit 1;;
16 esac