Patch-ID: bash40-021
[bash.git] / examples / scripts / vtree3
blob2059b9f407917233d21976d00382b43b86e7aa83
1 #!/bin/ksh
3 # Name: dirtree
4 # Programmer:
5 # Hemant T. Shah
6 # Life Insurance Data Processing
7 # July 12 1994
9 # Description:
10 # Print directory tree structure as follows:
11 # |___Mail
12 # |___scheduler
13 # |___cics_scripts
14 # |___tar_msdos
15 # |___awk
16 # |___attributes
17 # |___tmp
18 # |___News
19 # |___dosscsi
20 # |___FAQ_xterminal
21 # |___shell_history.Z
22 # |___FAQ_AIX
23 # |___aix_ftp_site
24 # |___hp_software
25 # |___dnload
26 # |___telnet.h
27 # |___msdos
28 # |___tnetd.tar.Z
29 # |___aix
30 # |___hp
31 # |___xkey.c
33 # Conversion to bash v2 syntax done by Chet Ramey
34 # - removed command substitutions calling `basename'
37 ProgramName=${0##*/}
38 Path="."
39 ShowAll=1
40 ShowDir=0
43 ExpandDirectory()
45 local object # Local variable
47 cd "$1"
49 for object in $PWD/.??* $PWD/*
51 if [ -d $object ]; # It is a directory
52 then
53 echo "${indent}|___${object##*/}/"
54 indent="${indent}! " # Add to indentation
55 if [ -x $object ];
56 then
57 ExpandDirectory $object
59 indent=${indent%????} # Remove from indentation
60 elif [ -e $object ]; then
61 if (( ShowAll == 1 ));
62 then
63 echo "${indent}|___${object##*/}"
66 done
70 usage()
72 echo -e "Usage: $ProgramName [-h] [-f] [-d] [path] "
73 echo -e "\t-h ... display this help message."
74 echo -e "\t-f path ... shows all files and directories below path (default)."
75 echo -e "\t-d path ... shows all directories only below path."
78 while getopts "fd" opt
80 case $opt in
81 f) ShowAll=1 ;;
82 d) ShowDir=1 ;;
83 *) usage ; exit 2;;
84 esac
85 done
87 shift $(( $OPTIND - 1 ))
89 Path=${1:-.}
91 if [ ! -d "$Path" ]; then
92 echo "$0: error: specified path is not a directory." >&2
93 exit 1
98 echo "!$Path/"
99 ExpandDirectory $Path