summaryrefslogtreecommitdiff
path: root/examples/scripts/vtree3
blob: 2059b9f407917233d21976d00382b43b86e7aa83 (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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#!/bin/ksh
#
# Name: dirtree
# Programmer:
#            Hemant T. Shah
#            Life Insurance Data Processing
#            July 12 1994
#
# Description:
#  Print directory tree structure as follows:
#   |___Mail
#     |___scheduler
#     |___cics_scripts
#     |___tar_msdos
#     |___awk
#     |___attributes
#   |___tmp
#   |___News
#     |___dosscsi
#     |___FAQ_xterminal
#     |___shell_history.Z
#     |___FAQ_AIX
#     |___aix_ftp_site
#     |___hp_software
#   |___dnload
#     |___telnet.h
#     |___msdos
#     |___tnetd.tar.Z
#     |___aix
#     |___hp
#   |___xkey.c
#
# Conversion to bash v2 syntax done by Chet Ramey
#	- removed command substitutions calling `basename'
#

ProgramName=${0##*/}
Path="."
ShowAll=1
ShowDir=0


ExpandDirectory()
{
local object   # Local variable

cd "$1"

for object in $PWD/.??* $PWD/*
do
   if [ -d $object ];  # It is a directory
   then
      echo "${indent}|___${object##*/}/"
      indent="${indent}!   "   # Add to indentation
      if [ -x $object ];
      then
         ExpandDirectory $object
      fi
      indent=${indent%????}    # Remove from indentation
   elif [ -e $object ]; then
      if (( ShowAll == 1 ));
      then
         echo "${indent}|___${object##*/}"
      fi
   fi
done

}

usage()
{
	echo -e "Usage: $ProgramName [-h] [-f] [-d] [path] "
	echo -e "\t-h       ... display this help message."
	echo -e "\t-f path  ... shows all files and directories below path (default)."
	echo -e "\t-d path  ... shows all directories only below path."
}

while getopts "fd" opt
do
	case $opt in
	f) ShowAll=1 ;;
	d) ShowDir=1 ;;
	*) usage ; exit 2;;
	esac
done

shift $(( $OPTIND - 1 ))

Path=${1:-.}

if [ ! -d "$Path" ]; then
	echo "$0: error: specified path is not a directory." >&2
	exit 1
fi



echo "!$Path/"
ExpandDirectory $Path