Skip to content

Instantly share code, notes, and snippets.

@vmx
Created October 12, 2022 10:15
Show Gist options
  • Save vmx/379608a299213b6e1df1e415a25e5b11 to your computer and use it in GitHub Desktop.
Save vmx/379608a299213b6e1df1e415a25e5b11 to your computer and use it in GitHub Desktop.
Takes a file and indents at `(` and `[`.
# SPDX-License-Identifier: MIT
#
# Takes a file and indents at `(` and `[`.
import sys
def main(argv=None):
if argv is None:
argv = sys.argv
if len(argv) != 2:
print("Usage: {} <file>".format(argv[0]))
inputpath = argv[1]
with open(inputpath, "r") as inputfile:
indent = 0
for char in inputfile.read():
print(char, end="")
if char in ["(", "["]:
indent += 1
print("\n" + " " * indent, end="")
elif char in [")", "]"]:
indent -= 1
print("\n" + " " * indent, end="")
if __name__ == "__main__":
sys.exit(main())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment