Created
December 28, 2015 21:26
-
-
Save vaijab/1b611fe1a79af828d8f3 to your computer and use it in GitHub Desktop.
Create index.html file listing from a given directory
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/bash | |
if [[ -d ${1} ]]; then | |
path="${1}/" | |
files="${path}*" | |
elif [[ -f ${1} ]]; then | |
files="${1}" | |
# Else fallback to finding files in current directory | |
elif [[ ${#} -eq 0 ]]; then | |
files="*" | |
fi | |
# heading | |
cat <<EOF > index.html | |
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> | |
<html> | |
<head> | |
</head> | |
<body> | |
<table id="listing"> | |
EOF | |
for f in ${files}; do | |
bn=$(basename "${f}") | |
if [[ ${bn} == *.html ]]; then | |
continue | |
elif [[ -d ${bn} ]]; then | |
continue | |
fi | |
echo " <tr class=\"item type-application type-octet-stream\">" >> index.html | |
echo " <td><a href=\"${bn}\">${bn}</a></td>" >> index.html | |
echo " </tr>" >> index.html | |
done | |
# footer | |
cat <<EOF >> index.html | |
</body> | |
</html | |
EOF |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment