Skip to content

Commit

Permalink
Fixed some loose ends
Browse files Browse the repository at this point in the history
  • Loading branch information
doekman committed Jan 28, 2018
1 parent 35b8f17 commit 0ff7cde
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 31 deletions.
27 changes: 15 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,32 @@ Based on [this answer by Daniel Trebbien][so-ascr-in-git] on stackoverflow and h



Configuration
-------------
Installation
------------

Install the filter by running the following command:
Either clone [this repository](https://github.com/doekman/osagitfilter), or download the [latest release](https://github.com/doekman/osagitfilter/releases).

./setup.sh install
Configure the filter by running the following command:

./setup.sh configure

Configure the filter by running [git config][gitconfig] (with or without the `--global` argument):

git config --global filter.osa.clean "osagitfilter --clean %f"
git config --global filter.osa.smudge "osagitfilter --smudge %f"
Make the filter available to git by running [git config][gitconfig] (with or without the `--global` argument):

git config --global filter.osa.clean "osagitfilter --clean"
git config --global filter.osa.smudge "osagitfilter --smudge"
git config --global filter.osa.required "true"


Put the line `*.scpt filter=osa` in your [gitattributes][], for example by running the following command from within your repository directory:
Put the line `*.scpt filter=osa` in your [gitattributes][] of your repository, for example by running the following command from within your repository directory:

echo "*.scpt filter=osa" >> .gitattributes

If you want to debug the script, use the following git config instead:

git config --global filter.osa.clean "osagitfilter --clean --log %f"
git config --global filter.osa.smudge "osagitfilter --smudge --log %f"
git config --global filter.osa.required "true"


[OSA]: https://developer.apple.com/library/content/documentation/AppleScript/Conceptual/AppleScriptX/Concepts/osa.html "Apple's Open Scripting Architecture"
Expand All @@ -38,7 +45,3 @@ Put the line `*.scpt filter=osa` in your [gitattributes][], for example by runni
[gitattributes]: https://git-scm.com/book/en/v2/Customizing-Git-Git-Attributes


Developer info
--------------

Because of the test files, don't enable `osagitfilter` for this `git`-repository.
15 changes: 15 additions & 0 deletions makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
BUILD=${CURDIR}/build
INCLUDE=osagetlang.sh osagitfilter.sh setup.sh README.md LICENSE

build: $(INCLUDE)
@[ -d $(BUILD) ] || mkdir -p $(BUILD)
zip $(BUILD)/osagitfilter.zip $^
tar -cvzf $(BUILD)/osagitfilter.tar.gz $^

clean:
@rm -Rf build

test:
${CURDIR}/test.sh

.PHONY: clean test
12 changes: 2 additions & 10 deletions osagetlang.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,12 @@ use AppleScript version "2.4"
use framework "Foundation"
use framework "OSAKit"

on print line_text
--On some systems, scripting additions contains a definition for NSURL (where XMLLib.osax is included in scripting additions)
--We need this elsewhere, so scoping like this works.
using terms from scripting additions
do shell script "echo " & quoted form of line_text
end using terms from
end print

on run args
if (count of args) is not 1 then error "usage: osagetlang.applescript path-to-script-file.scpt" number 1
if (count of args) is not 1 then error "usage: osagetlang path-to-script-file.scpt" number 1
set scpt_path to item 1 of args
set source_nsurl to current application's NSURL's fileURLWithPath:scpt_path
set the_script to current application's OSAScript's alloc()'s initWithContentsOfURL:source_nsurl |error|:(missing value)
if the_script is missing value then error "File or contained script is unreachable" number 1
set osa_lang to the_script's language()'s |name| as text
print osa_lang
get osa_lang
end run
24 changes: 19 additions & 5 deletions osagitfilter.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env bash

SCRIPT_VER=0.4
SCRIPT_VER=0.5

function finish {
#SCRATCH is initialized to a temp directory only at the moment it's needed
Expand All @@ -18,9 +18,23 @@ trap finish EXIT
################

function usage {
echo "---=[ $SCRIPT_NAME - v$SCRIPT_VER ]=----------------------------------------------"
echo "usage: $SCRIPT_NAME --clean [--forbidden FORBIDDEN] [FILE] #translates OSA script to text, FORBIDDEN is colon-seperated"
echo " $SCRIPT_NAME --smudge [FILE] #translates text to OSA script"
echo "usage: $SCRIPT_NAME command [options] [FILE]"
echo
echo "command (use one):"
echo " --clean Translates OSA script to text, to be put into git"
echo " --smudge Translates text stored in git to OSA script"
echo
echo "arguments (all optional):"
echo " -f, --forbidden Provide forbidden languages. '-' for empty list, defaults to 'AppleScript Debugger'"
echo " -n, --no-header Don't write a OSA-lang header when it's the default language"
echo " -d, --debug Write debug info to stderr"
echo " -l, --log Write debug info to '$LOG_PATH/$SCRIPT_NAME.log'"
echo " -h, -?, --help Show this help message and exit"
echo " -v, --version Show program's version number and exit"
echo " FILE Filename of current stream. Useful for debuggin only"
echo
echo "This script translates input from stdin to stdout only. The options '--forbidden' and '--no-header' "
echo "are only used with the '--clean' command."
if [[ $# > 0 ]]; then
ERROR 1 "$@"
fi
Expand Down Expand Up @@ -58,7 +72,7 @@ while (( $# > 0 )) ; do
-d | --debug) DEBUG=1;;
-l | --log) DEBUG=2;;
-h | -\? | --help) usage;;
-v | --version) echo $SCRIPT_VER;exit 0;;
-v | --version) echo "$SCRIPT_NAME v$SCRIPT_VER";exit 0;;
-*) usage "Unrecognized switch '$1'";;
*) FILE=$1;;
esac
Expand Down
2 changes: 1 addition & 1 deletion setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ BASE_DIR=$(pwd)
INSTALL_INTO=/usr/local/bin
COMMANDS='osagetlang osagitfilter'

if [[ $1 = install ]]; then
if [[ $1 = configure ]]; then
echo "Trying to install the osagitfilter-commands"
for CMD in $COMMANDS; do
if [[ -f $INSTALL_INTO/$CMD ]]; then
Expand Down
20 changes: 17 additions & 3 deletions test-files/usage.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
---=[ osagitfilter - v0.4 ]=----------------------------------------------
usage: osagitfilter --clean [--forbidden FORBIDDEN] [FILE] #translates OSA script to text, FORBIDDEN is colon-seperated
osagitfilter --smudge [FILE] #translates text to OSA script
usage: osagitfilter command [options] [FILE]

command (use one):
--clean Translates OSA script to text, to be put into git
--smudge Translates text stored in git to OSA script

arguments (all optional):
-f, --forbidden Provide forbidden languages. '-' for empty list, defaults to 'AppleScript Debugger'
-n, --no-header Don't write a OSA-lang header when it's the default language
-d, --debug Write debug info to stderr
-l, --log Write debug info to '/Users/doekman/Library/Logs/Catsdeep//osagitfilter.log'
-h, -?, --help Show this help message and exit
-v, --version Show program's version number and exit
FILE Filename of current stream. Useful for debuggin only

This script translates input from stdin to stdout only. The options '--forbidden' and '--no-header'
are only used with the '--clean' command.

0 comments on commit 0ff7cde

Please sign in to comment.