Skip to content

Instantly share code, notes, and snippets.

@thingsiplay
Created February 4, 2025 15:16
Show Gist options
  • Save thingsiplay/889cb2899f35405e10839112f5181ab3 to your computer and use it in GitHub Desktop.
Save thingsiplay/889cb2899f35405e10839112f5181ab3 to your computer and use it in GitHub Desktop.
toarchive - Create one archive for each file or folder (Bash using 7z)
#!/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