sunburnt
What I mean with 'build complete' is that the list must be completely built by bash each time user click on a directory.
This draft only gives a picture how it could be solved.
It is not tested or complete.
1. List directories in <table>.
<table><variable>DIR</variable><labels>"|directory structure"</label><input>cat /tmp/dirs</input>
I would use a command like:
Code: Select all
find "$DIR" -maxdepth 1 -mindepth 1 -type d -follow -printf " %p|%f/\n" | sort > /tmp/dirs
The trick here is to list full path of directories in first column, and then hide the column with the given <label>.
2. Add a + in front of all directories that includes subdirectories. Others gets a -.
I suggest here to use sed, but since it is a very slow command, you should probably search for a faster solution.
Code: Select all
cut -c 3 /tmp/dirs > /tmp/dirs2 #get rid of spaces added by -printf command
while read I; do
NAME=`basename "$I"`
if [ -d "`ls -1 --group-directories-firs "$I" | head -n 1`" ]; then
sed -i -e "s%|$NAME%|+ $NAME%g" /tmp/dirs
else
sed -i -e "s%|$NAME%|- $NAME%g" /tmp/dirs
fi
done < /tmp/dirs2
3. User click on a + directory and the list must expand with the given sublevel
Code: Select all
BEFORE="`grep --before-context=1000 -w "$DIR" /tmp/dirs`"
AFTER="`grep --after-context=1000 -w "$DIR" /tmp/dirs`"
SUBLEVEL="`find "$DIR" -maxdepth 1 -mindepth 1 -type d -follow -printf " %p| %f/\n" | sort`"
echo -e "$BEFORE\n$DIR\n$SUBLEVEL\$AFTER" > /tmp/dirs
4. Clear and Refresh <table>