#!/bin/sh # Create an archive autodetecting the archive type based on filename # Usage: archive a.tar.gz files... # If no extension is given, you will be prompted for one. archive() { name="$1" shift case "$name" in *.tar) realpath --relative-to="$(pwd)" --zero "$@" | tar cvf "$name" --verbatim-files-from --files-from=/dev/stdin;; *.tar.gz|*.tgz) realpath --relative-to="$(pwd)" --zero "$@" | tar cvzf "$name" --verbatim-files-from --files-from=/dev/stdin;; *.cbr|*.rar) realpath --relative-to="$(pwd)" --zero "$@" | xargs -0 rar -r "$name";; *.cbz|*.zip) realpath --relative-to="$(pwd)" --zero "$@" | xargs -0 zip -r "$name";; *) name="$name.$(printf '%s\n' tar.gz zip rar cbr cbz tar | fzy -p "Choose type: ")" archive "$name" "$@";; esac } archive "$@"