Skip to content

Instantly share code, notes, and snippets.

@mahodder
Created March 14, 2013 14:38
Show Gist options
  • Save mahodder/5161856 to your computer and use it in GitHub Desktop.
Save mahodder/5161856 to your computer and use it in GitHub Desktop.
Adds a new option to your Mac "Services" menu to zip selected folder without including .git, .DS_Store files - created zip file takes folder name. To Setup: - Search for automator on your Mac and open it - Double click "Service" - Double click Library -> Utilities -> Run Shell Script - "Services Receives selected" dropdown should be set to "file…
declare -a names
declare -a parts
declare i=0
names=("$@")
name="$1"
while x=$(dirname "$name"); [ "$x" != "/" ]
do
parts[$i]="$x"
i=$(($i + 1))
name="$x"
done
for prefix in "${parts[@]}" /
do
for name in "${names[@]}"
do
if [ "${name#$prefix/}" = "${name}" ]
then continue 2
fi
done
dir="$prefix"
break
done
cd "$dir"
for file in "${names[@]}"
do
zip ${file#$dir/}.zip -r "${file#$dir/}" -x *.DS_Store *.git*
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment