Skip to content

Instantly share code, notes, and snippets.

@1lastBr3ath
Created November 4, 2020 14:53
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 1lastBr3ath/a41bf7d800d9ab0f6134779db046718a to your computer and use it in GitHub Desktop.
Save 1lastBr3ath/a41bf7d800d9ab0f6134779db046718a to your computer and use it in GitHub Desktop.
GitHub pre-commit hook to generate tree structure of documents along with hyperlink
#!/usr/bin/env bash
README="${1:-README.md}"
HEAD="$(head -n5 "$README")"
cat > "$README" <<< "$HEAD"
#echo "## Table of Contents" >> "$README"
tree -f --dirsfirst --noreport -I README.md | sed -r '1d; s#\.\/(.+)#[\1]\(<./\1\>)#g; s#\[[^]/]+\/#[#g; s/$/ /g' >> "$README"
git add "$README"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment