Skip to content

Instantly share code, notes, and snippets.

@wware
Created November 14, 2014 13:20
Show Gist options
  • Save wware/7d4fb8725ff9e689ccf3 to your computer and use it in GitHub Desktop.
Save wware/7d4fb8725ff9e689ccf3 to your computer and use it in GitHub Desktop.
This helps to build a swish.conf file for use with swish-e, which can then help to quickly search a large project for keywords.
#!/usr/bin/env python
"""
Example usage:
find . -type f | head -3000 | ./suffixes.py
Use this to build a swish.conf file for swish-e, e.g:
IndexDir .
IndexOnly .h .qml .cpp .png .pro .qmlproject .svg .jpg .qdoc .qrc .json .js .sci .xml .pri .desktop .txt
IndexContents TXT* .h .qml .cpp .png .pro .qmlproject .svg .jpg .qdoc .qrc .json .js .sci .xml .pri .desktop .txt
"""
import sys
d = {}
while True:
L = sys.stdin.readline()
if L.startswith("./"):
L = L[2:]
if not L:
break
L = L.rstrip()
try:
n = L.rindex(".")
except ValueError:
continue
L = L[n+1:]
if L not in d:
d[L] = 1
else:
d[L] += 1
lst = [(-pop, suf) for suf, pop in d.items()]
lst.sort()
for pop, suf in lst:
print suf, -pop
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment