#!/usr/bin/env python

import os
import sys
# if you pip installed this is wrong but you have silent_tools installed anyways
silent_tools_dir = os.path.dirname(os.path.realpath(__file__))
if silent_tools_dir not in sys.path:
    sys.path.append(silent_tools_dir)

import silent_tools
from silent_tools import eprint

# Don't throw an error when someone uses head
from signal import signal, SIGPIPE, SIG_DFL
signal(SIGPIPE, SIG_DFL) 

if (len(sys.argv) == 1):
    eprint("")
    eprint('silentorigls by bcov - a tool to allow you to "ls" a silent file')
    eprint('     but see the original names if there are duplicates')
    eprint("Usage:")
    eprint("        silentls myfile.silent")
    sys.exit(1)


files = sys.argv[1:]


for ifile in range(len(files)):

    file = files[ifile]

    if (len(files) > 1):
        print(file + ":")

    silent_index = silent_tools.get_silent_index( file )

    for tag in silent_index["orig_tags"]:
        print(tag)

    if (ifile + 1 < len(files)):
        print("")

