Skip to content

Instantly share code, notes, and snippets.

@jeremyvisser
Created July 2, 2015 12:52
Show Gist options
  • Save jeremyvisser/e1f0ed6bd051b1ebed4b to your computer and use it in GitHub Desktop.
Save jeremyvisser/e1f0ed6bd051b1ebed4b to your computer and use it in GitHub Desktop.
IOS–like "section" command
#!/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