Skip to content

Instantly share code, notes, and snippets.

@mastensg
Created September 9, 2013 20:23
Show Gist options
  • Save mastensg/6500982 to your computer and use it in GitHub Desktop.
Save mastensg/6500982 to your computer and use it in GitHub Desktop.
Tabular git-annex whereis
#!/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 = 4
repolen = max(map(len, repos)) + padding
pathlen = cols - repolen * len(repos) - padding
for path in paths:
line = path.ljust(pathlen)[:pathlen] + padding * " "
for repo in repos:
if path in repos[repo]:
line += repo.ljust(repolen)
else:
line += "".ljust(repolen)
print(line)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment