Last active
December 27, 2022 18:52
-
-
Save PlugFox/e4e4f73358247a882754ccda94267381 to your computer and use it in GitHub Desktop.
cbz.sh is a simple command line shell script (bash) to take a folder and turn it into a comic book zip archive (a zip archive with a cbz file name extension instead of zip).
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
#! /bin/zsh | |
# Usage: Zips given directories into .cbz (Comic Book ZIP) archives of the smame name (eg "folder name.cbz"). | |
# How to make public: | |
# 1. chmod +x cbz.sh | |
# 2. mv cbz.sh /usr/local/bin/cbz | |
# 3. cbz -h | |
complete="/System/Applications/Music.app/Contents/Resources/complete.aif" | |
remove_flag="m" | |
recursive_flag="r" | |
test_flag="T" | |
symlink_flag="y" | |
compression="9" | |
open_flag="false" | |
while getopts "kho" flag | |
do | |
case $flag in | |
"k") #clears remove flag | |
echo "Keeping originals." | |
remove_flag="" | |
;; | |
"h") #print usage | |
echo "USAGE: cbz [-k][-h] DIRECTORY…" | |
echo "-h print this help screen" | |
echo "-k keep originals" | |
#echo "-o output directory" | |
exit 0 | |
;; | |
esac | |
done | |
for target in "$@" | |
do | |
if [[ -e $target ]] #exists | |
then | |
if [[ -r $target ]] #readable | |
then | |
if [[ -d $target ]] #directory | |
then | |
archive=${target%/} | |
echo "Archiving: $target" | |
echo "zip -$remove_flag$recursive_flag$test_flag$symlink_flag$compression \"$archive.cbz\" \"$target\" -x \"*.DS_Store\" \"*[Tt]humbs.db\"" | |
# -m delete originals, -r recursive, -T test zip, -y store symlink, -9 maximum compression, -x exclude list | |
zip -"$remove_flag$recursive_flag$test_flag$symlink_flag$compression" "$archive.cbz" "$target" -x "*.DS_Store" "*[Tt]humbs.db" | |
else | |
echo "Not a directory: $target" | |
fi #-d | |
else | |
echo "Not readable: $target" | |
fi #-r | |
else | |
echo "Not found: $target" | |
fi #-e | |
done | |
#When done play the iTunes done sound. | |
if [[ -e $complete && -r $complete ]] | |
then | |
afplay "$complete" | |
else | |
echo "Sorry, the complete sound \"$complete\" could not be found or read." | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment