Created
October 12, 2022 10:15
-
-
Save vmx/379608a299213b6e1df1e415a25e5b11 to your computer and use it in GitHub Desktop.
Takes a file and indents at `(` and `[`.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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