Skip to content

Instantly share code, notes, and snippets.

@mastensg
Created September 9, 2013 21:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mastensg/6501551 to your computer and use it in GitHub Desktop.
Save mastensg/6501551 to your computer and use it in GitHub Desktop.
whereis alternative
#!/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