public
Last active

Remove the comments automatically added by Xcode 4.4 to newly created files

  • Download Gist
removeXcodeTemplateFluff.sh
Shell
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
#!/bin/bash
 
# WARNING: USE AT YOUR OWN RISK
# requires SUDO
# Ideally, the Templates in the user's home directory should override the
# defaults, but I can't get this to work for Xcode 4.4, hence the following
# !! WORKAROUND !! hacky solution to edit them in place
#
# And this does not work completely, the files added when the default project
# is created seem to be unaffected, only subsequently added files are.
 
set -e
 
# http://www.bobmccune.com/2012/03/04/creating-custom-xcode-4-file-templates/
export X1="/Applications/Xcode.app/Contents/Developer/Library/Xcode/Templates"
export X2="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/Xcode/Templates"
 
# For Debugging
set -x && set -v && set -o verbose
 
function replaceTemplate() { \
cp -r "$1" "$1.bak"
find -E "$1" -type f -regex '.*\.(c|h|m)' -exec sed -i '' '1,/^$/d' '{}' ';'
}
 
replaceTemplate $X1
replaceTemplate $X2

This is a bit dangerous. The first time around you might want to manually browse to the correct folders and run the following

find -E . -type f -regex '.*\.(c|h|m)' -exec sed -i '' '1,/^$/d' '{}' ';'

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.