Created
September 9, 2013 21:08
-
-
Save mastensg/6501551 to your computer and use it in GitHub Desktop.
whereis alternative
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 | |
import subprocess | |
import sys | |
repos = {} | |
paths = [] | |
command = ["git", "annex", "whereis"] + sys.argv[1:] | |
output = subprocess.check_output(command) | |
for line in output.split("\n")[:-1]: | |
if line.startswith("ok"): | |
continue | |
if line.startswith("whereis"): | |
path = " ".join(line.split(" ")[1:-3]) | |
paths.append(path) | |
continue | |
repo = line.split(" -- ")[-1].split()[0] | |
if not repo in repos: | |
repos[repo] = [] | |
repos[repo].append(path) | |
cols = int(subprocess.check_output(["tput", "cols"])) | |
padding = 1 | |
pathlen = cols - len(repos) - padding | |
for i in range(len(repos)): | |
print(i * "|" + "," + repos.keys()[i]) | |
print(len(repos) * "|") | |
for path in paths: | |
line = "" | |
for repo in repos: | |
if path in repos[repo]: | |
line += "X" | |
else: | |
line += "_" | |
line += " " + path.ljust(pathlen)[:pathlen] | |
print(line) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment