#!/usr/bin/env bash 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 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 Affero General Public License for more details. # # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . usage="DIR_ID [NAME [PREFIX [LAST]]]" . "${0%/*}/_shlib.sh" 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 local a b c if locale -k LC_MESSAGES | grep -xF 'messages-codeset="UTF-8"' >/dev/null; then a='├── ' b='│   ' c='└── ' else a='|-- ' b='| ' c='`-- ' fi 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 "$@"