-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsquash_lines.py
More file actions
39 lines (28 loc) · 1010 Bytes
/
squash_lines.py
File metadata and controls
39 lines (28 loc) · 1010 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/usr/bin/env python3
import argparse
def convert_one_line(filepath):
file_input = open(filepath, 'r')
output = ''
for line in file_input.readlines():
if line.isspace():
continue
if line.lstrip().startswith('#'):
continue
line_stripped = line.rstrip()
if line_stripped.endswith(('do', 'done', 'then', 'else', 'fi')):
output = output + line_stripped + ' '
elif line_stripped.endswith(';'):
output = output + line_stripped + ' '
else:
output = output + line_stripped + '; '
print(output)
file_input.close()
def main():
parser = argparse.ArgumentParser(description='convert a multiline shell script to a single line')
parser.add_argument("-f", "--filepath", type=str,
help="full path to the multiline shell script")
args = parser.parse_args()
convert_one_line(filepath=args.filepath)
return
if __name__ == "__main__":
main()