Skip to content

Instantly share code, notes, and snippets.

@sc0ttkclark
Last active March 3, 2024 09:22
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save sc0ttkclark/660655fea6916cd41bdc46c4fdb0d033 to your computer and use it in GitHub Desktop.
Save sc0ttkclark/660655fea6916cd41bdc46c4fdb0d033 to your computer and use it in GitHub Desktop.
PhpStorm.app (Toolbox) Mac integration with Tower.app for diff and merge

Toolbox PhpStorm.app Mac integration with Tower.app for diff and merge

How to use this

  1. Add CompareTools.plist and phpstorm-toolbox.sh files in the ~/Library/Application Support/com.fournova.Tower3/CompareTools/ directory. You may need to mkdir ~/Library/Application\ Support/com.fournova.Tower3/CompareTools if the folder does not already exist
  2. Update the phpstorm-toolbox.sh to use your username for the /Users/yourusername/ path and the correct version number (PhpStorm > About > Build #PS-XXX.XXXXX.XX where XXX.XXXXX.XX is the version number to use).
  3. Run chmod +x ~/Library/Application\ Support/com.fournova.Tower3/CompareTools/phpstorm-toolbox.sh
  4. Go into Tower.app Preference > Git Config > Select "PhpStorm" for "Diff tool" and "Compare tool", you can optionally enable "Perform directory diff"

Other variations

Credits

While I went and figured out how to do all of this, this integration is based on the one I found for Beyond Compare's beta integration: https://github.com/tednaleid/git-tower-beyond-compare-shim

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN"
"http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<array>
<dict>
<key>ApplicationIdentifier</key>
<string>com.jetbrains.PhpStorm</string>
<key>ApplicationName</key>
<string>PhpStorm</string>
<key>DisplayName</key>
<string>PhpStorm (Toolbox)</string>
<key>LaunchScript</key>
<string>phpstorm-toolbox.sh</string>
<key>Identifier</key>
<string>phpstorm</string>
<key>SupportsMergeTool</key>
<true/>
<key>SupportsDiffChangeset</key>
<true/>
</dict>
</array>
</plist>
#! /usr/bin/env bash
# Shell script shim to let PhpStorm.app (Toolbox) to integrate with Tower.app
#
# Tower.app gives us these parameters:
LOCAL="$1"
REMOTE="$2"
PATH_USERNAME="yourusername"
APP_VERSION="222.4345.15"
APPLICATION_PATH="/Users/$PATH_USERNAME/Library/Application Support/JetBrains/Toolbox/apps/PhpStorm/ch-0/$APP_VERSION/PhpStorm.app"
CMD="$APPLICATION_PATH/Contents/MacOS/phpstorm"
# Sanitize LOCAL path
if [[ ! "$LOCAL" =~ ^/ ]]; then
LOCAL=$(echo "$LOCAL" | sed -e 's/^\.\///')
LOCAL="$PWD/$LOCAL"
fi
# Sanitize REMOTE path
if [[ ! "$REMOTE" =~ ^/ ]]; then
REMOTE=$(echo "$REMOTE" | sed -e 's/^\.\///')
REMOTE="$PWD/$REMOTE"
fi
MERGING="$4"
BACKUP="/tmp/$(date +"%Y%d%m%H%M%S")"
if [ -n "$MERGING" ]; then
BASE="$3"
MERGE="$4"
# Sanitize BASE path
if [[ ! "$BASE" =~ ^/ ]]; then
BASE=$(echo "$BASE" | sed -e 's/^\.\///')
BASE="$PWD/$BASE"
if [ ! -f "$BASE" ]; then
BASE=/dev/null
fi
fi
# Sanitize MERGE path
if [[ ! "$MERGE" =~ ^/ ]]; then
MERGE=$(echo "$MERGE" | sed -e 's/^\.\///')
MERGE="$PWD/$MERGE"
if [ ! -f "$MERGE" ]; then
# For conflict "Both Added", Git does not pass the merge param correctly in current versions
MERGE=$(echo "$LOCAL" | sed -e 's/\.LOCAL\.[0-9]*//')
fi
fi
sleep 1 # required to create different modification timestamp
touch "$BACKUP"
"$CMD" merge "$LOCAL" "$REMOTE" "$BASE" "$MERGE"
else
"$CMD" diff "$LOCAL" "$REMOTE"
fi
if [ -n "$MERGING" ]; then
# Check if the merged file has changed
if [ "$MERGE" -ot "$BACKUP" ]; then
exit 1
fi
fi
exit 0
@sc0ttkclark
Copy link
Author

If I had more time, I would make this handle more dynamically like https://github.com/vdmorozov/mac-jetbrains-sudo-launcher/blob/master/mac-jb-sudo.applescript does. Unfortunately right now it requires you specify the username and version number manually due to how Toolbox installs the app.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment