aboutsummaryrefslogtreecommitdiff
path: root/lib/keyringer/actions/tree
blob: a87754877af86d7e009bf6c4c0fd02016a44f530 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/usr/bin/env bash
#
# List keys, tree version.
#

# Thanks http://www.centerkey.com/tree/
function keyringer_tree {
  find $* | sed -e 's/[^-][^\/]*\//|  /g' | sed -r -e 's/\|  ([^|])/|- \1/'
}

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

# Aditional parameters
CWD="`pwd`"

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

# on *BSD, find expects at least one argument with the path
if [ "$ARGS" == "" ]; then
  ARGS="./"
fi

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

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