Skip to content

Instantly share code, notes, and snippets.

@k06a
Last active April 5, 2016 11:33
Show Gist options
  • Save k06a/ba09d35b877eb255b1ce to your computer and use it in GitHub Desktop.
Save k06a/ba09d35b877eb255b1ce to your computer and use it in GitHub Desktop.
Reorder property attributes script
#
# Reorder property attributes in one possible way
#
# @property (nullable, readonly, assign, nonatomic, getter=isReady) BOOL ready;
#
# 1. Move readonly to the BEGIN of attribute list
# 2. Move nullable to the BEGIN of attribute list
# 3. Move null_resettable to the BEGIN of attribute list
# 4. Move nonatomic to the END of attribute list
# 5. Move getter to the END of attribute list
#
find . -type f \( -iname \*.m -o -iname \*.mm -o -iname \*.h \) -print0 | xargs -0 /usr/bin/sed -i '' 's#(\([^)]*\),[ ]*readonly)#(readonly, \1)#g; s#(\([^)]*\),[ ]*readonly,[ ]*\([^)]*\))#(readonly, \1, \2)#g; s#(\([^)]*\),[ ]*nullable)#(nullable, \1)#g; s#(\([^)]*\),[ ]*nullable,[ ]*\([^)]*\))#(nullable, \1, \2)#g; s#(\([^)]*\),[ ]*null_resettable)#(null_resettable, \1)#g; s#(\([^)]*\),[ ]*null_resettable,[ ]*\([^)]*\))#(null_resettable, \1, \2)#g; s#(nonatomic,[ ]*\([^)]*\))#(\1, nonatomic)#g; s#(\([^)]*\),[ ]*nonatomic,[ ]*\([^)]*\))#(\1, \2, nonatomic)#g; s#(getter=\([^), ]*\),[ ]*\([^)]*\))#(\2, getter=\1)#g; s#(\([^)]*\),[ ]*getter=\([^), ]*\),[ ]*\([^)]*\))#(\1, \3, getter=\2)#g'
# Check only modified and untracked git files
git status --porcelain | sed s/^...// | grep -E '(.*\.h|.*\.m|.*\.mm)$' | xargs /usr/bin/sed -i '' 's#(\([^)]*\),[ ]*readonly)#(readonly, \1)#g; s#(\([^)]*\),[ ]*readonly,[ ]*\([^)]*\))#(readonly, \1, \2)#g; s#(\([^)]*\),[ ]*nullable)#(nullable, \1)#g; s#(\([^)]*\),[ ]*nullable,[ ]*\([^)]*\))#(nullable, \1, \2)#g; s#(\([^)]*\),[ ]*null_resettable)#(null_resettable, \1)#g; s#(\([^)]*\),[ ]*null_resettable,[ ]*\([^)]*\))#(null_resettable, \1, \2)#g; s#(nonatomic,[ ]*\([^)]*\))#(\1, nonatomic)#g; s#(\([^)]*\),[ ]*nonatomic,[ ]*\([^)]*\))#(\1, \2, nonatomic)#g; s#(getter=\([^), ]*\),[ ]*\([^)]*\))#(\2, getter=\1)#g; s#(\([^)]*\),[ ]*getter=\([^), ]*\),[ ]*\([^)]*\))#(\1, \3, getter=\2)#g'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment