Skip to content

Instantly share code, notes, and snippets.

@sdcampbell
Last active February 12, 2023 15:32
Show Gist options
  • Save sdcampbell/854788ad0a7a02b3ba105aa827dadc09 to your computer and use it in GitHub Desktop.
Save sdcampbell/854788ad0a7a02b3ba105aa827dadc09 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
import sys
#remove comments from PowerShell scripts
currently_code = True
with open(sys.argv[1], 'r') as readtest:
psup_contents = readtest.readlines()
with open(sys.argv[1], 'w') as removed:
for line in psup_contents:
line = line.lstrip()
if line.startswith("#") and not line.startswith("#>"):
pass
elif line.startswith("<#"):
currently_code = False
elif line.startswith('\n'):
pass
elif line.startswith("#>"):
currently_code = True
else:
if currently_code:
removed.write(line)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment