Created
November 14, 2014 13:20
-
-
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.
This file contains hidden or 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 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