Created
July 2, 2015 12:52
-
-
Save jeremyvisser/e1f0ed6bd051b1ebed4b to your computer and use it in GitHub Desktop.
IOS–like "section" command
This file contains 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
#!/usr/bin/env python3 | |
import sys | |
if len(sys.argv) <= 1: | |
print('usage: %s <search text>' % sys.argv[0], file=sys.stderr, flush=True) | |
sys.exit(1) | |
search = ' '.join(sys.argv[1:]) | |
search_indent = -1 | |
for line in sys.stdin: | |
line_indent = len(line) - len(line.lstrip()) | |
line = line.rstrip() | |
if search_indent >= 0 and line_indent > search_indent and len(line) > 0: | |
print(line) | |
else: | |
search_indent = -1 | |
if search in line: | |
search_indent = line_indent | |
print(line) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment