Skip to content

Instantly share code, notes, and snippets.

@gedankenexperimenter
Last active March 24, 2022 04:57
Show Gist options
  • Save gedankenexperimenter/258d26d36085aa408c3a4f23dd839b76 to your computer and use it in GitHub Desktop.
Save gedankenexperimenter/258d26d36085aa408c3a4f23dd839b76 to your computer and use it in GitHub Desktop.
The equivalent of how I added namespace comments to Kaleidoscope source code
#!/usr/bin/env bash
cd "${KALEIDOSCOPE_DIR}"
cat > .clang-format <<EOF
---
BasedOnStyle: Google
---
Language: Cpp
FixNamespaceComments: true
KeepEmptyLinesAtTheStartOfBlocks: true
ReflowComments: false
EOF
fd '.*\.(h|cpp)$' src --print0 | xargs -0 clang-format -i
fd '.*\.(h|cpp)$' plugins --print0 | xargs -0 clang-format -i
git add --all && git commit -m "temporary clang-format"
perl -pi -e 's/(Fix.*:) true/$1 false/' .clang-format
fd '.*\.(h|cpp)$' src --print0 | xargs -0 clang-format -i
fd '.*\.(h|cpp)$' plugins --print0 | xargs -0 clang-format -i
git stash push -m "clang-format namespace comments"
git reset --hard HEAD^
git stash pop
# Manual review and fixup
@gedankenexperimenter
Copy link
Author

Note: I did not actually run this script; I used magit in Emacs and edited the .clang-format file by hand. I've been using fd lately instead of find, and I was too lazy to convert it for this gist. And perl instead of sed because mac OS sed -i doesn't do what you'd want it to, and I can never remember the regex syntax for it. There may be errors.

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