summaryrefslogtreecommitdiff
path: root/modules/blobs/tree.sh
diff options
context:
space:
mode:
Diffstat (limited to 'modules/blobs/tree.sh')
-rw-r--r--modules/blobs/tree.sh94
1 files changed, 64 insertions, 30 deletions
diff --git a/modules/blobs/tree.sh b/modules/blobs/tree.sh
index a13b320..f08db42 100644
--- a/modules/blobs/tree.sh
+++ b/modules/blobs/tree.sh
@@ -1,40 +1,74 @@
#!/usr/bin/env bash
-name='tree'
-ver=0.1
-# Copyright (C) 2010, 2016 Luke Shumaker
+name=bolbs/tree
+desc='Recursively show the directory tree of a blob ID'
+copyright=('2010, 2016 Luke Shumaker')
+license=('AGPLv3+')
+# This file is part of rvs.
#
-# This program is free software; you can redistribute it and/or
-# modify it under the terms of the GNU General Public License as
-# published by the Free Software Foundation; either version 2 of the
-# License, or (at your option) any later version.
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-# General Public License for more details.
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
#
-# You should have received a copy of the GNU General Public License
-# along with this program; see the file COPYING.
-# If not, see <http://www.gnu.org/licenses>.
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
-. "${0%/*}/_stdio.sh"
+usage="DIR_ID [NAME [PREFIX [LAST]]]"
+. "${0%/*}/_shlib.sh"
-usage="DIR_ID [NAME] [PREFIX] [LAST]"
-id="`getvar "$1"`"
-name="${2-.}"
-pref="$3"
-last="$4"
+main() {
+ local id name prefix has_prefix last
+ case $# in
+ 0) errusage;;
+ 1) id=$1; name=.;;
+ 2) id=$1; name=$2;; prefix=''; has_prefix=false;;
+ 3) id=$1; name=$2;; prefix=$3; has_prefix=true;;
+ 3) id=$1; name=$2;; prefix=$3; has_prefix=true; last=$4;;
+ *) errusage;;
+ esac
-echo "$pref $name $id"
-pref=' | '
-"$RVS" ls "$id" '%i\t%n' | while read line; do
- i="`echo "$line" | cut -f1`"
- n="`echo "$line" | cut -f2-`"
- t="`"$RVS" blob-gettype "$i"`"
- if [ "$t" = 'd' ]
- "$RVS" tree "$i" "$n" "$pref"
+ local a b c
+ if locale -k LC_MESSAGES | grep -xF 'messages-codeset="UTF-8"' >/dev/null; then
+ a='├── '
+ b='│   '
+ c='└── '
else
- echo "$pref $n $i"
+ a='|-- '
+ b='| '
+ c='`-- '
fi
-done
+ local pfix_self pfix_chld
+ if ! $has_prefix; then
+ pfix_self=''
+ pfix_chld=''
+ else
+ pfix_self="$prefix$a"
+ pfix_chld="$prefix$b"
+ if [[ -n "$last" ]]; then
+ pfix_self="$prefix$c"
+ fi
+ fi
+
+ printf "%s$(_ '%s\t(%s)')\n" "$pfix_self" "$name" "$id"
+ if [[ "$id" == d:* ]]; then
+ local lastname
+ lastname="$("$RVS" get.d "$id" /dev/stdout | sed -n '$/.*\t//p')"
+ local perm user group id name
+ while read -r perm user group id name; do
+ if [[ "$name" != "$lastname" ]]; then
+ "$RVS" tree "$id" "$name" "$pfix_chld"
+ else
+ "$RVS" tree "$id" "$name" "$pfix_chld" t
+ fi
+ done < <("$RVS" get.d "$id" /dev/stdout)
+ fi
+
+}
+
+main "$@"