Skip to content

Instantly share code, notes, and snippets.

@mchinen
Last active August 29, 2015 13:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mchinen/10437124 to your computer and use it in GitHub Desktop.
Save mchinen/10437124 to your computer and use it in GitHub Desktop.
WIP shell script to fix slightly off indentation of control statements (for mac)
#!/usr/bin/env bash
# Cleans up almost k&r formated control statements to nicer ones, e.g.
# if (something){ -> if (something)
# while(something){ -> while (something) {
#
# Probably doesn't work on lots of things and has holes and will destroy your computer, use at your own risk.
# It worked for me on two files
#
# Usage:
# ./thenameofthisfile.sh MyInputFileThatIsSupposedToBeKR.c
sed -E -i -e 's/(if|while|else if|for) ?\((.*)\) ?{/\1 (\2) {/' $1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment