#!/bin/bash
#
# List keys.
#

# Thanks http://www.centerkey.com/tree/
function keyringer_tree {
  ls -R $* | grep ":$" | sed -e 's/:$//' -e 's/[^-][^\/]*\//--/g' -e 's/^/   /' -e 's/-/|/'
}

# Load functions
LIB="`dirname $0`/../functions"
source "$LIB" || exit 1

# Aditional parameters
CWD="`pwd`"

# Avoid leading slash
shift
ARGS="`echo "$*" | sed -e "s|^/*||"`"

# Check implementation
if which tree &> /dev/null; then
  TREE="tree"
else
  TREE="keyringer_tree"
fi

# Run list command
cd "$KEYDIR" && $TREE $ARGS
cd "$CWD"
