Created
February 4, 2025 15:16
-
-
Save thingsiplay/889cb2899f35405e10839112f5181ab3 to your computer and use it in GitHub Desktop.
toarchive - Create one archive for each file or folder (Bash using 7z)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# Create one archive for each file or folder. | |
if [ "${#}" -eq -1 ]; then | |
echo "toarchive ext files..." | |
echo "toarchive zip *.smc" | |
else | |
ext="${1}" | |
shift | |
opt=() | |
stop_parse=false | |
for arg in "${@}"; do | |
if [ ! "${stop_parse}" == true ]; then | |
if [ "${arg}" == "--" ]; then | |
stop_parse=true | |
opt+=(--) | |
continue | |
elif [[ "${arg}" =~ ^- ]]; then | |
opt+=("${arg}") | |
continue | |
fi | |
fi | |
file="${arg}" | |
7z a "${opt[@]}" "${file}.${ext}" "${file}" | |
done | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment