Skip to content

Instantly share code, notes, and snippets.

@sburlot
Created March 8, 2014 15:03
Show Gist options
  • Star 24 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save sburlot/9431843 to your computer and use it in GitHub Desktop.
Save sburlot/9431843 to your computer and use it in GitHub Desktop.
Creates a ramdisk and start Xcode with the DerivedData stored in ramdisk. Also deletes the ramdisk and reset Xcode prefs.
#!/bin/bash
# Creates a ramdisk and start Xcode with the DerivedData stored in ramdisk. Also deletes the ramdisk and reset Xcode prefs.
# xc_ramdisk.sh
# - creates a ramdisk, set Xcode DerivedData to this disk and start Xcode.
# - umount a ramdisk, set Xcode DerivedData to default
# Stephan Burlot, Coriolis Technologies, http://www.coriolis.ch
#
# based on Alex Shevchenko xcode_ramdisk.sh script (https://gist.github.com/skeeet/2367298)
# based on Diego Freniche xc-launch.sh script (https://github.com/dfreniche/xc-launch)
# mount point for the ramdisk volume
ramdisk='/Volumes/ramdisk'
# size of created disk in M-bytes
disk_size=1024
# compute the size of the disk in 512-byte sectors
rdsize=$(($disk_size*1024*1024/512))
StartService () {
cmd="\$3 == \"$ramdisk\" {print \$3}"
if [[ $(mount | awk "$cmd") != "" ]]; then
echo "$ramdisk is already mounted, erasing ramdisk."
rm -rf /Volumes/ramdisk
else
diskutil erasevolume HFS+ "ramdisk" `hdiutil attach -nomount ram://$rdsize`
fi
# set the Derived Data folder in Xcode prefs
/usr/bin/defaults write com.apple.dt.Xcode IDECustomDerivedDataLocation "$ramdisk"
open -a Xcode
}
StopService () {
if [ -z "$(pgrep Xcode)" ]; then
cmd="\$3 == \"$ramdisk\" {print \$3}"
if [[ $(mount | awk "$cmd") != "" ]]; then
# reset the Derived Data folder in Xcode prefs to default
/usr/bin/defaults delete com.apple.dt.Xcode IDECustomDerivedDataLocation
# eject disk
hdiutil detach $ramdisk
else
echo "$ramdisk is not mounted"
fi
else
echo "Xcode is running, nothing done."
fi
}
RestartService () {
ConsoleMessage "Restarting, nothing will be done here..."
}
# Test for arguments.
if [ -z $1 ]; then
echo "Usage: $0 [start|stop] "
exit 1
fi
# Source the common setup functions for startup scripts
test -r /etc/rc.common || exit 1
. /etc/rc.common
RunService "$1"
@yuhua-chen
Copy link

works like a charm~ thanks so much 😄

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