Last active
February 10, 2024 06:14
-
-
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
This file contains hidden or 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 | |
#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}" |
This file contains hidden or 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
#!/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}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage:
tree_to_markdown.sh PATH_TO_DIR
Example:
tree_to_markdown.sh .