#!/bin/sh # # $Id: tree,v 1.1 2004/03/08 20:58:43 dope Exp dope $ # # No comments and no support from my side! usage() { echo "$0 [-d] [-r \"regex\"] [directory]" >&2 echo " -d only directories" >&2 echo " -r directories/files matching regex" >&2 } tree() { if [ ! -x "$1" ] then echo "-x\c" exit fi cd $1 set -f set "" `ls -a 2>/dev/null` || { echo "-r\c"; exit; } shift if [ $# -eq 2 ] then echo "-\c" fi args="$*" argus="" if [ -n "$OPTION" ] then case $OPTION in *d*) for i in $args do [ -d "$i" ] && argus="$argus $i" done args="$argus" argus="";; esac case $OPTION in *r*) for i in $args do if [ -d "$i" ] || case $i in $ra) :;; *) false;; esac then argus="$argus $i" fi done args="$argus" argus="";; esac fi if [ -n "$args" ] then set "" `ls -adF $args 2>/dev/null` else set "" fi shift while [ -n "$2" ] do if [ "$1" != "./" -a "$1" != "../" ] then echo "\n${striche}|----$1\c" if [ -d "$1" ] then (striche="${striche}| "; tree $1 ) fi fi shift done if [ -n "$1" -a "$1" != "./" -a "$1" != "../" ] then if [ -d "$1" ] then echo "\n${striche}\`----$1\c" striche="${striche} "; tree $1 else echo "\n${striche}\`----$1\n${striche}\c" fi fi } trap 'echo; exit' 0 1 2 3 15 while getopts dr: opt do case $opt in d) OPTION="${OPTION}d";; r) OPTION="${OPTION}r";ra="$OPTARG";; \?) usage; exit 1;; esac done shift `expr $OPTIND - 1` dir=${1:-`pwd`} if [ ! -d "$dir" ] then echo "$0: $dir is not a Directory" >&2 exit 1 fi echo "$dir\c" tree $dir fi