Created
August 13, 2021 14:59
-
-
Save ipedro/73bd5cf39493ed07d6f4bb600a09166c to your computer and use it in GitHub Desktop.
Post-checkout hook clear DerivedData and re-open Xcode if needed
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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