Giter Club home page Giter Club logo

cansakirt / dirdoc Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 15 KB

DirDoc: A powerful Bash script that generates comprehensive Markdown documentation of directory structures and file contents. Ideal for project snapshots, code reviews, and documentation automation.

Home Page: https://cansakirt.github.io/DirDoc/

License: MIT License

Shell 100.00%
automation bash-script code-review command-line developer-tools directory-tree documentation-generator file-system markdown project-snapshot

dirdoc's Introduction

DirDoc: Directory Documentation Generator

License: MIT Bash Version

Table of Contents

Introduction

DirDoc is a powerful and flexible Bash script designed to create a comprehensive markdown file containing the contents of all text files within a specified directory. It also provides a visual representation of the directory structure, making it an invaluable tool for documentation and code review processes.

This script is particularly useful for:

  • Generating documentation for software projects
  • Creating snapshots of directory contents for archival purposes
  • Facilitating code reviews by providing an easy-to-navigate markdown file of the entire project

Quick Start

  1. Download the script:

    curl -O https://raw.githubusercontent.com/cansakirt/DirDoc/main/dirdoc.sh
    
  2. Make it executable:

    chmod +x dirdoc.sh
    
  3. Run it on a directory:

    ./dirdoc.sh /path/to/your/directory
    
  4. Find the generated markdown file in your current directory.

Features

  • Generates a markdown file with contents of all text files in a directory
  • Creates a visual tree-like representation of the directory structure
  • Allows exclusion of files based on patterns
  • Supports limiting the depth of directory traversal
  • Provides debug output for troubleshooting
  • Utilizes parallel processing for improved performance on multi-core systems
  • Customizable output file naming

Requirements

  • Bash shell (version 4.0 or later recommended)
  • Standard Unix utilities: find, grep, xargs, file, date, nproc

Installation

  1. Download the script:
    curl -O https://raw.githubusercontent.com/cansakirt/DirDoc/main/dirdoc.sh
    
  2. Make the script executable:
    chmod +x dirdoc.sh
    

Usage

Basic Usage

./dirdoc.sh /path/to/your/directory

This will generate a markdown file named your-directory_YYYYMMDD_HHMMSS.md in the current working directory.

Options

  • -o, --output FILE: Specify the output file name
  • -e, --exclude PATTERN: Exclude files matching the given pattern (can be used multiple times)
  • -d, --debug: Enable debug output
  • -m, --max-depth DEPTH: Maximum depth to recurse (default: unlimited)
  • -h, --help: Display help message and exit

Examples

  1. Basic usage:

    ./dirdoc.sh /path/to/your/directory
    
  2. Specify output file:

    ./dirdoc.sh -o project_docs.md /path/to/your/directory
    
  3. Exclude all .log files:

    ./dirdoc.sh -e "*.log" /path/to/your/directory
    
  4. Exclude multiple file types (log and tmp):

    ./dirdoc.sh -e "*.log" -e "*.tmp" /path/to/your/directory
    
  5. Limit directory traversal to 3 levels:

    ./dirdoc.sh -m 3 /path/to/your/directory
    
  6. Exclude hidden files and directories:

    ./dirdoc.sh -e "*/.*" /path/to/your/directory
    
  7. Exclude specific directory:

    ./dirdoc.sh -e "*/node_modules/*" /path/to/your/directory
    
  8. Combine multiple options:

    ./dirdoc.sh -o project_docs.md -e "*.log" -e "*/.*" -m 3 -d /path/to/your/directory
    

Code Walkthrough

For a detailed walkthrough of the script's main components, please refer to the comments within the dirdoc.sh file.

Customization

You can customize the script by modifying the following aspects:

  • Change the default timestamp format in the TIMESTAMP variable.
  • Modify the create_tree function to alter the tree representation.
  • Adjust the process_file function to change how file contents are formatted in the markdown output.

Troubleshooting

  1. Script not running:

    • Ensure the script has execute permissions: chmod +x dirdoc.sh
  2. Files not being processed:

    • Check if the files are readable by the user running the script.
    • Verify that the files are recognized as text files by the file command.
  3. Slow performance:

    • For large directories, try using the -m option to limit the depth of traversal.
    • Ensure your system has multiple CPU cores to benefit from parallel processing.
  4. Unexpected exclusions:

    • Use the -d option to enable debug output and see which files are being processed or excluded.

Contributing

Contributions to improve the script are welcome! Please follow these steps:

  1. Fork the repository.
  2. Create a new branch for your feature or bug fix.
  3. Make your changes and commit them with clear, descriptive messages.
  4. Push your changes and create a pull request.

For more details, please see the CONTRIBUTING.md file.

FAQ

Q: Can DirDoc handle large directories with many files?

A: Yes, DirDoc uses parallel processing to handle large directories efficiently. However, for extremely large directories, you may want to use the -m option to limit the depth of traversal.

Q: Is it possible to exclude certain file types or directories?

A: Absolutely! You can use the -e option to exclude files or directories based on patterns. For example, -e "*.log" will exclude all .log files.

Q: Can I customize the output format?

A: The current version outputs in Markdown format. If you need a different format, you can modify the process_file function in the script. We're considering adding more output formats in future versions.

Q: Does DirDoc work on Windows?

A: DirDoc is designed for Unix-like systems. It may work on Windows using WSL (Windows Subsystem for Linux) or Git Bash, but it's not officially supported on Windows.

Q: How can I contribute to DirDoc?

A: We welcome contributions! Please see our CONTRIBUTING.md file for guidelines on how to contribute.

License

This script is released under the MIT License. See the LICENSE file for details.


We hope DirDoc enhances your documentation and code review processes. If you have any questions or suggestions, please open an issue in the repository. Happy documenting!

dirdoc's People

Contributors

cansakirt avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.