Skip to content

Instantly share code, notes, and snippets.

@frankus
Created August 13, 2015 00:14
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save frankus/f13830ea658bed55ca41 to your computer and use it in GitHub Desktop.
Save frankus/f13830ea658bed55ca41 to your computer and use it in GitHub Desktop.
Updates Xcode's default file-header comment to correct filename
find . -iname '*.[mh]' -print0 | while IFS= read -r -d '' file; do basename=`basename "$file"`; sed -i .bak "2s|// .*\$|// $basename|" "$file"; done
@frankus
Copy link
Author

frankus commented Aug 13, 2015

A few notes:

  1. Make sure you have a backup
  2. This will look at every .h and .m file and if the second line starts with two slashes followed by two spaces, it will replace the entire line with two slashes followed by two spaces, followed by the basename of the file (i.e. -lastPathComponent).
  3. If you're in a YOLO mood, replace the string .bak with an empty set of quotes (''). Otherwise you can clean up the .bak files with find . -iname '*.bak' -exec rm "{}" \;.
  4. There's probably a better way to do this, even short of Apple building this into their refactoring tools.

@frankus
Copy link
Author

frankus commented Oct 24, 2022

Updated for Swift files:

find . -iname '*.swift' -print0 | while IFS= read -r -d '' file; do basename=`basename "$file"`; sed -i .bak "2s|//  .*\$|//  $basename|" "$file"; done

@frankus
Copy link
Author

frankus commented Oct 24, 2022

To delete backup files:

find . -name "*.bak" -delete

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