Skip to content

Instantly share code, notes, and snippets.

@ipedro
Created August 13, 2021 14:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ipedro/73bd5cf39493ed07d6f4bb600a09166c to your computer and use it in GitHub Desktop.
Save ipedro/73bd5cf39493ed07d6f4bb600a09166c to your computer and use it in GitHub Desktop.
Post-checkout hook clear DerivedData and re-open Xcode if needed
#!/bin/bash
PROCESS=Contents/MacOS/Xcode
WORKSPACE={Your Workspace/Project Path}
CACHE=~/Library/Developer/Xcode/DerivedData
# --------
previousHead=$1
currentHead=$2
if [ $previousHead == $currentHead ]
then
# same branch, ignoring...
exit 0
fi
function clean() {
echo "Cleaning $1..."
rm -rf $1
}
function stop() {
echo "Killing $1"
kill $(ps aux | grep -v grep | grep $1 | awk '{print $2}' | xargs -L 1 kill -9)
}
function reopen() {
echo "Re-Opening $1..."
open $1
}
function isOpen() {
filename=${0##*/}
number=$(ps aux | grep -v grep | grep -v $filename | grep -ci $1)
if [ $number -gt 0 ]
then
echo "Found $number open instances of $1"
return 0
else
return 1
fi
}
if isOpen $PROCESS; then
stop $PROCESS
clean $CACHE
reopen $WORKSPACE
else
clean $CACHE
fi
#!/bin/bash
previousHead=$1
currentHead=$2
if [ $previousHead == $currentHead ]
then
# same branch, ignoring...
exit 0
fi
process=Contents/MacOS/Xcode
workspace={Your Workspace/Project Path}
cache=~/Library/Developer/Xcode/DerivedData
{Path to script}/stop-and-frisk.sh $process $workspace $cache
#!/bin/bash
PROCESS=$1
WORKSPACE=$2
CACHE=$3
function clean() {
echo "Cleaning $1..."
rm -rf $1
}
function stop() {
echo "Killing $1"
kill $(ps aux | grep -v grep | grep $1 | awk '{print $2}' | xargs -L 1 kill -9)
}
function reopen() {
echo "Re-Opening $1..."
open $1
}
function isOpen() {
filename=${0##*/}
number=$(ps aux | grep -v grep | grep -v $filename | grep -ci $1)
if [ $number -gt 0 ]
then
echo "Found $number open instances of $1"
return 0
else
return 1
fi
}
if isOpen $PROCESS; then
stop $PROCESS
clean $CACHE
reopen $WORKSPACE
else
clean $CACHE
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment