git-ascr-filter

from http://stackoverflow.com/a/14425009
This commit is contained in:
Maciej Krok 2016-09-22 21:51:16 +02:00
parent dbd9cdace6
commit 9b8a02d9d4
3 changed files with 32 additions and 0 deletions

2
.gitattributes vendored Normal file
View File

@ -0,0 +1,2 @@
*.scpt filter=ascr

30
scripts/git-ascr-filter Executable file
View File

@ -0,0 +1,30 @@
#!/bin/sh
if [ $# -ne 2 ]; then
echo "Usage: $0 --clean/--smudge FILE">&2
exit 1
else
if [ "$1" = "--clean" ]; then
osadecompile "$2" | sed 's/[[:space:]]*$//'
elif [ "$1" = "--smudge" ]; then
TMPFILE=`mktemp -t tempXXXXXX`
if [ $? -ne 0 ]; then
echo "Error: \`mktemp' failed to create a temporary file.">&2
exit 3
fi
if ! mv "$TMPFILE" "$TMPFILE.scpt" ; then
echo "Error: Failed to create a temporary SCPT file.">&2
rm "$TMPFILE"
exit 4
fi
TMPFILE="$TMPFILE.scpt"
# Compile the AppleScript source on stdin.
if ! osacompile -l AppleScript -o "$TMPFILE" ; then
rm "$TMPFILE"
exit 5
fi
cat "$TMPFILE" && rm "$TMPFILE"
else
echo "Error: Unknown mode '$1'">&2
exit 2
fi
fi

Binary file not shown.