Skip to content

Instantly share code, notes, and snippets.

@praveen-palanisamy
Last active February 10, 2024 06:14
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save praveen-palanisamy/31795f2680bc3ade04dd8d78d8651ee9 to your computer and use it in GitHub Desktop.
Save praveen-palanisamy/31795f2680bc3ade04dd8d78d8651ee9 to your computer and use it in GitHub Desktop.
Convert output of tree utility to Markdown in a pretty format. Useful to display code/directory structure
#!/usr/bin/env bash
#File: tree2githubmd
#Description: Convert output of unix tree utility to Github flavoured Markdown
tree=$(tree -f --noreport --charset ascii $1 |
sed -e 's/| \+/ /g' -e 's/[|`]-\+/ */g' -e 's:\(* \)\(\(.*/\)\([^/]\+\)\):\1[\4](\2):g')
printf "# Code/Directory Structure:\n\n${tree}"
#!/bin/bash
#File: tree2md
#Description: Convert output of tree utility to Markdown in a pretty format
tree=$(tree -f --noreport --charset ascii $1 |
sed -e 's/| \+/ /g' -e 's/[|`]-\+/ */g' -e 's:\(* \)\(\(.*/\)\([^/]\+\)\):\1[\4](\2):g' -e 's/^\( \* \)/├──/gm' -e 's/^\( \* \)/ └──/gm' -e 's/^\( \* \)/ └──/gm')
printf "# Code Struct:\n\n${tree}"
@praveen-palanisamy
Copy link
Author

Usage: tree_to_markdown.sh PATH_TO_DIR

Example: tree_to_markdown.sh .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment