From: Chris Koeritz Date: Fri, 15 Feb 2013 16:38:04 +0000 (-0500) Subject: nice fix to allow a list of directories to be passed on the command line. X-Git-Tag: 2.140.90~1110 X-Git-Url: https://feistymeow.org/gitweb/?a=commitdiff_plain;h=c52707a6e170cd357e07a7c10f33c06f9e836d2d;p=feisty_meow.git nice fix to allow a list of directories to be passed on the command line. --- diff --git a/scripts/files/zip_directories.sh b/scripts/files/zip_directories.sh index c3aee860..4204bc80 100644 --- a/scripts/files/zip_directories.sh +++ b/scripts/files/zip_directories.sh @@ -5,18 +5,39 @@ source $FEISTY_MEOW_SCRIPTS/core/functions.sh -#hmmm: take a dir parameter to go to for this. -dir=. +dirs=() +# snag the command line arguments into an array of names. +for i in "$@"; do dirs+=("$i"); done + +# if there were no arguments, use the current directories list of directories. +if [ ${#dirs[@]} -eq 0 ]; then + # using a temp file is clumsy but after a lot of different methods being tried, this one + # worked and wasn't super ugly. + tempfile="$(mktemp /tmp/dirlist.XXXXXX)" + find $dir -mindepth 1 -maxdepth 1 -type d -exec echo "dirs+=(\"{}\");" ';' >$tempfile + source "$tempfile" +echo dirs default to: ${dirs[@]} + \rm -f $tempfile +fi + +# takes a directory name as an argument and sucks the directory +# into a timestamped zip file. function flattenizer() { - while read dirname; do - if [ ! -z "$dirname" ]; then - echo "flattening directory '$dirname'..." + for dirname in "$@"; do + while [[ $dirname =~ .*/$ ]]; do + dirname="${dirname:0:((${#dirname}-1))}" + done + if [ ! -z "$dirname" -a -d "$dirname" ]; then + echo "flattening '$dirname'..." zip -rm "${dirname}_$(date_stringer)" "$dirname" &>/dev/null fi done } -find $dir -mindepth 1 -maxdepth 1 -type d | flattenizer +for ((i=0; i < ${#dirs[@]}; i++)); do + dir="${dirs[i]}" + flattenizer "$dir" +done