Skip to content

Instantly share code, notes, and snippets.

@bennokress
Last active February 27, 2024 20:14
Show Gist options
  • Save bennokress/4cf38810ce712e5abf42a95caf38370f to your computer and use it in GitHub Desktop.
Save bennokress/4cf38810ce712e5abf42a95caf38370f to your computer and use it in GitHub Desktop.
Integration Script to get JuxtaCode Support in Tower
#!/bin/sh
# CHECK IF JUXTA IS INSTALLED AS A COMMAND LINE TOOL #
# Set CMD to where the juxta is in the PATH of the environment.
CMD=`which juxta`
# If that didn't produce any results we search for juxta at the default path.
if [ -z "$CMD" ] ; then
if [ -e '/usr/local/bin/juxta' ] ; then
CMD='/usr/local/bin/juxta'
fi
fi
# The last check is if juxta is executable at the determined path.
if [ ! -x "$CMD" ]; then
echo "JuxtaCode's command line tool 'juxta' is not executable. Please make sure it has been installed in /usr/local/bin/." >&2
exit 128
fi
# PARSE ARGUMENTS #
FIRST="$1"
SECOND="$2"
THIRD="$3"
# Sanitize Arguments
if [[ ! "$FIRST" =~ ^/ ]]; then
FIRST=$(echo "$FIRST" | sed -e 's/^\.\///')
FIRST="$PWD/$FIRST"
fi
if [[ ! "$SECOND" =~ ^/ ]]; then
SECOND=$(echo "$SECOND" | sed -e 's/^\.\///')
SECOND="$PWD/$SECOND"
fi
if [[ ! "$THIRD" =~ ^/ ]]; then
THIRD=$(echo "$THIRD" | sed -e 's/^\.\///')
THIRD="$PWD/$THIRD"
fi
# DETERMINE TOOL TYPE - DIFF OR MERGE #
if [ $# -eq 3 ]; then
# 3 ARGUMENTS → DIFF #
# The "base" argument is going to be deprecated over time.
"$CMD" _difftool --base "$THIRD" --local "$FIRST" --remote "$SECOND" --merged "$THIRD"
elif [ $# -eq 4 ]; then
# 4 ARGUMENTS → MERGE #
FOURTH="$4"
if [[ ! "$FOURTH" =~ ^/ ]]; then
FOURTH=$(echo "$FOURTH" | sed -e 's/^\.\///')
FOURTH="$PWD/$FOURTH"
if [ ! -f "$FOURTH" ]; then
# For conflict "Both Added", Git does not pass the merge param correctly in current versions
MERGE=$(echo "$FIRST" | sed -e 's/\.LOCAL\.[0-9]*//')
fi
fi
"$CMD" _mergetool --base "${1}" --local "${2}" --remote "${3}" --merged "${4}"
else
# CATCH INVALID ARGUMENT COUNT #
echo "Expected either 3 or 4 arguments."
exit 1
fi
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment