#!/bin/bash
ProgramName=${0Path="."
ShowAll=1
ShowDir=0
ExpandDirectory()
{
local object
cd "$1"
for object in $PWD/.??* $PWD/*
do
if [ -d $object ]; then
echo "${indent}|___${object##*/}/"
indent="${indent}! " if [ -x $object ];
then
ExpandDirectory $object
fi
indent=${indent%????} 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) ShowAll=0 ;;
*) 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