Skip to content

Instantly share code, notes, and snippets.

@vaijab
Created December 28, 2015 21:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vaijab/1b611fe1a79af828d8f3 to your computer and use it in GitHub Desktop.
Save vaijab/1b611fe1a79af828d8f3 to your computer and use it in GitHub Desktop.
Create index.html file listing from a given directory
#!/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