So, I wrote my own.
Here's a bash script that is a simplified version of the tree utility.
#!/bin/bash
tree() {
local prefix=$1
local dir=$2
local count=`ls -l $dir | wc -l`
if [[ $count -eq 0 ]]
then
return
fi
local i=1
local bar="|"
local nextPrefix="| "
for file in "$dir"/*
do
i=$(($i + 1))
if [[ $i -eq $count ]]
then
bar="\`"
nextPrefix=" "
fi
filename=$(basename $file)
echo "$prefix$bar---$filename"
if [[ -d $file ]]
then
tree "$prefix$nextPrefix" $file
fi
done
}
if [[ -z $1 ]]
then
dir=`pwd`
else
dir=$1
fi
if [[ ! -e $dir ]]
then
echo "Directory $dir does not exist"
exit 1
elif [[ ! -d $dir ]]
then
echo "$dir is not a directory"
exit 2
fi
basename $dir
tree "" $dir
No comments:
Post a Comment