Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
shell script to work as middleware between Sketch and and git repo. syntax: 'upload.sh [filename] "optional commit message"'
#!/bin/sh
# some parts of this forked from https://github.com/blended/sketch-collaboration
# cf. https://github.com/chadlavi/sketch-collaboration
if [ ! `command -v jq` ]; then
echo "you need to install jq. If you use Homebrew, try 'brew install jq'"
exit 1
fi
if [ -z "$1 ]; then
echo "syntax:"
echo "upload.sh [filename] \"optional commit message\""
exit 1
fi
sketch_file=$1
sketch_file_base="$(basename $sketch_file)"
sketch_dir="${sketch_file_base%.*}"
return=`pwd`
cd "$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
# Pull the latest changes from the repo
git pull
# Unzip the file
unzip -o "$sketch_file" -d "$sketch_dir"
# prettify JSON
for file in ./$sketch_dir/*.json; do
jq . $file | sed 's:/:\\/:g' > "$file.bak"
mv "$file.bak" "$file"
done
# Remove the preview file
rm -Rf ./$sketch_dir/previews/
git add .
if [ -z "$2" ]; then
git commit -m "Update (`date`)"
else
git commit -m "$2 (`date`)"
fi
git push
cd "$return"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment