Is there a way to represent a directory tree in a Github README.md?

后端 未结 14 1762
庸人自扰
庸人自扰 2020-12-22 17:03

In my Githubs repos documentation I want to represent a directory tree structure like this:

\"enter

相关标签:
14条回答
  • 2020-12-22 17:43

    For those who want a quick solution:

    There is a way to get a output to the console similar to the output from tree, by typing the following command into your terminal:

    ls -R YOURFOLDER | grep ':$' | sed -e 's/:$//' -e 's/[^\/]*\//|  /g' -e 's/|  \([^|]\)/|–– \1/g' 
    

    This alternative is mentioned in this documentation: https://wiki.ubuntuusers.de/tree/

    Then the output can be copied and encapsuled inside a .md file with code block back tics, like mentioned in Jonathas B.C.'s answer.

    But be aware that it also outputs all node modules folders in a node project. And in tree you can do something like

    tree -I node_modules
    

    to exlude the node modules folder.

    0 讨论(0)
  • 2020-12-22 17:44

    Not directly, no. You'd have to hand create it and put it in yourself. Assuming you are using a *nix box locally and are using utf, then tree will generate it nicely (I believe that is what generated the example you used above).

    Assuming you mean the readme.md as the documentation target, then I think the only way you could automate it would be a git pre-commit hook that ran tree and embedded it into your readme file. You'd want to do a diff to make sure you only updated the readme if the output changed.

    Otoh if you are maintaining seperate docs via github pages, then what you could do, is switch to using jekyll (or another generator) locally and pushing the static pages yourself. Then you could potentially implement the changes you want either as a plugin / shell script* / manual changes (if they won't vary much), or use the same method as above.

    *If you integrate it into a commit hook, you can avoid adding any extra steps to changing your pages.

    0 讨论(0)
  • 2020-12-22 17:50

    The best way to do this is to surround your tree in the triple backticks to denote a code block. For more info, see the markdown docs: http://daringfireball.net/projects/markdown/syntax#code

    0 讨论(0)
  • 2020-12-22 17:50

    You can also check this tree-extended package. It can be used as a command line app by using node >= 6.x.

    It is very similar to tree but also has the option of configuring the max deep in the tree, that is one of the awful things of it. Also you can filter by using .gitignore file.

    0 讨论(0)
  • 2020-12-22 17:50

    Insert command tree in bash.

    Also, there is a DOS comnand "tree". You can displays directory paths and files in each subdirectory with command:

    tree /F
    

    https://web.csulb.edu/~murdock/tree.html

    0 讨论(0)
  • 2020-12-22 17:53

    I got resolver the problem in this way:

    1. Insert command tree in bash.

    Example

    1. Create a README.md in github repository and copy bash result
    2. Insert in .md file within markdown code

    Example

    4. See the output and be happy =)

    0 讨论(0)
提交回复
热议问题