Skip to content

Instantly share code, notes, and snippets.

@shollingsworth
Last active February 10, 2022 01:39
Show Gist options
  • Save shollingsworth/55642e0877ff0cfec8288b2eaa8457b2 to your computer and use it in GitHub Desktop.
Save shollingsworth/55642e0877ff0cfec8288b2eaa8457b2 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""breakout a bash command into lines."""
import select
import sys
from textwrap import indent
def main():
"""Run main function."""
if select.select([sys.stdin], [], [], 0.0)[0]:
content = sys.stdin.read()
else:
raise SystemExit("No STDIN detected!")
lines = content.splitlines()
sep = " "
for line in lines:
spl = line.split()
beg = spl.pop(0)
out = " \\\n".join(spl)
print(f"{beg} \\\n{indent(out, prefix=sep)}")
print()
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment