code / scripts

Lines748 Shell528 Python72 Lua67 Bourne Again Shell62 make15
1 others 4
Markdown4
(22 lines)
1 #!/bin/sh
2 # Create an archive autodetecting the archive type based on filename
3 # Usage: archive a.tar.gz files...
4 # If no extension is given, you will be prompted for one.
5 archive() {
6 name="$1"
7 shift
8 case "$name" in
9 *.tar)
10 realpath --relative-to="$(pwd)" --zero "$@" | tar cvf "$name" --verbatim-files-from --files-from=/dev/stdin;;
11 *.tar.gz|*.tgz)
12 realpath --relative-to="$(pwd)" --zero "$@" | tar cvzf "$name" --verbatim-files-from --files-from=/dev/stdin;;
13 *.cbr|*.rar)
14 realpath --relative-to="$(pwd)" --zero "$@" | xargs -0 rar -r "$name";;
15 *.cbz|*.zip)
16 realpath --relative-to="$(pwd)" --zero "$@" | xargs -0 zip -r "$name";;
17 *)
18 name="$name.$(printf '%s\n' tar.gz zip rar cbr cbz tar | fzy -p "Choose type: ")"
19 archive "$name" "$@";;
20 esac
22 archive "$@"