Project Files to Nested Markdown Checkboxes

Compatibility: MacOS

The following script will generate a markdown file with checkboxes for all the files and directories in the current directory. This is useful when you are going through a new project and want to keep track of what you have gone through.

❯ tree --dirsfirst | sed -e 's/[├──└│]/ /g' > ~/projects_as_md_checkboxes.txt

--dirsfirst will list directories first, and sed -e 's/[├──└│]/ /g' will remove the tree characters from the output.

Why --dirsfirst? Because my IDE shows directories first, and I want to keep the same order in the markdown file. 

def tree_to_markdown(tree_file):
    with open(tree_file, 'r') as f:
        lines = f.readlines()
    markdown_list = []
    for line in lines:
        leading_spaces = len(line) - len(line.lstrip())
        name = line.lstrip()
        checkbox = ' ' * leading_spaces + '- [ ] ' + name
    markdown_output = ''.join(markdown_list)
    return markdown_output

tree_file_path = '/Users/saif/projects_as_md_checkboxes.txt'
markdown_output = tree_to_markdown(tree_file_path)