diff --git a/content/technical/2011/08/strip-trailing-whitespace-xcode-4.html b/content/technical/2011/08/strip-trailing-whitespace-xcode-4.html new file mode 100644 index 0000000..4cdcd4d --- /dev/null +++ b/content/technical/2011/08/strip-trailing-whitespace-xcode-4.html @@ -0,0 +1,29 @@ +Xcode has a bad habit of adding trailing whitespace to code, which is a pet +peeve of mine. It introduces irrelevant changes into diffs and is particularly +glaring when commiting code with [GitX], which highlights it in red. In [TextMate] +and now [Vico] I have bound the strip trailing whitespace in current document +action to ⌃⌥⌘S (control-option-command-s). This makes it quick and easy. +Xcode makes adding these types of actions a bit harder but I came up with a +solution that uses the Behaviours functionality in Xcode 4. This is how I did +it: + +[GitX]: http://gitx.frim.nl/ +[Vico]: http://www.vicoapp.com/ +[TextMate]: http://macromates.com/ + +Create a shell script that invokes `sed` on each git tracked file that is +modified. Since Xcode doesn't tell the script what the current file was and +I didn't want to run sed over every file every time, processing tracked files +with modifications was the best solution I could come up with. Note that the +script also only prcocesses `.m` and `.h` files. I have my copy of the script +in `~/Documents/strip.sh`, be sure to give it the execute permission. + + + +Next you need to add a behaviour to Xcode. Go to the Xcode preferences and +click the Behaviours section, then click the + button. Name the behaviour and +give it a keyboard shortcut. In the right pane check Run and choose the script +you saved above. That's it. Now you can kill off that nasty whitespace with +ease. + +Xcode 4 Behaviours Preferences diff --git a/content/technical/2011/08/strip-trailing-whitespace-xcode-4.yaml b/content/technical/2011/08/strip-trailing-whitespace-xcode-4.yaml new file mode 100644 index 0000000..aff6434 --- /dev/null +++ b/content/technical/2011/08/strip-trailing-whitespace-xcode-4.yaml @@ -0,0 +1,15 @@ +--- +title: Strip Trailing Whitespace in Xcode 4 +extra: How to create a behaviour in Xcode 4 to strip trailing whitespace from all git tracked files with changes. +kind: article +section: technical +created_at: 2011-08-27 19:36:00 +keywords: +- xcode +- strip +- trailing +- whitespace +- text +- editing +- programming +- apple diff --git a/output/images/2011/08/xcode-behaviours-preferences-small.png b/output/images/2011/08/xcode-behaviours-preferences-small.png new file mode 100644 index 0000000..3e67fb1 Binary files /dev/null and b/output/images/2011/08/xcode-behaviours-preferences-small.png differ diff --git a/output/images/2011/08/xcode-behaviours-preferences.png b/output/images/2011/08/xcode-behaviours-preferences.png new file mode 100644 index 0000000..587bc29 Binary files /dev/null and b/output/images/2011/08/xcode-behaviours-preferences.png differ