Created
May 1, 2017 10:03
-
-
Save gentam/42bee765753fd8e9be4b8fb8277c7c55 to your computer and use it in GitHub Desktop.
print files and directories tree in HTML list
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
echo "<!DOCTYPE html><html lang=\"en\"><head><meta charset=\"UTF-8\">\ | |
<title>Directory Tree</title></head><body>" | |
find . \ | |
| tail -n +2 | sed -e '/\/\./d' \ | |
| awk -F/ ' | |
BEGIN { preNF = 0 } | |
{ | |
if (NF > preNF) print "<ul>" | |
if (NF < preNF) { | |
diff = preNF - NF | |
while (diff--) print "</ul>" | |
} | |
printf "<li><a href=\"%s\">%s</a></li>\n", $0, $NF | |
preNF = NF | |
} | |
END { while (--preNF) print "</ul>" }' | |
echo "</body></html>" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment