#!/bin/bash
#
# outputs folder structure as a nested
HTML list
# HTML list contains specific markup used by JQuery's treeview plugin
# about treeview see: http://plugins.jquery.com/project/treeview
#
# know issues:
# o does not work with whitespaces in dir/file names
#
# author: Sebastian Stein (http://sebstein.hpfsc.de/)
# date: 2009-07-12
# version: 1.0
# license: LGPL 3.0 (2007-06-29)
#
# homepage:
# http://www.soa-bpm-integration.com/2009-07-12-dateibaeume-drupal-jquery-darstellen
#
#
# ChangeLog
#
# 2009-07-13 - generate JavaScript call above list, too
#
# 2009-07-12 - initial version
# outputs content of folder as treeview list
# recursive function: calls itself while stumbling across a directory
#
# parameter: content of a directory formated as a list
function goFolder {
tab=$tab"\t"
for currFile in "$@";
do
if [ -z "$thisFile" ];
then
thisFile="$currFile"
else
thisFile="$thisFile"/"$currFile"
fi
if [ -d "$thisFile" ];
then
# current file is a folder; output and go into it
echo -e $tab''$currFile''
if [ -n "`command ls "$thisFile"`" ];
then
tab=$tab"\t"
echo -e $tab''
goFolder $(command ls --group-directories-first "$thisFile")
echo -e $tab'
'
tab=${tab%"\t"}
fi
echo -e $tab''
else
# current file is a file; only output it
echo -e $tab''$currFile''
fi
thisFile=${thisFile%/*}
done
tab=${tab%"\t"}
}
####################
# script starts here
####################
# compute an ID for the tree
treeId=`date | md5sum | sed -e "s/\ \ -//"`
echo ''
echo ''
goFolder `command ls`
echo '
'