| Crates.io | dirgrab |
| lib.rs | dirgrab |
| version | 0.2.0 |
| created_at | 2025-04-01 21:37:31.726808+00 |
| updated_at | 2025-04-02 18:40:53.045033+00 |
| description | CLI tool to concatenate file contents from directories, respecting Git context. |
| homepage | |
| repository | https://github.com/rileyleff/dirgrab |
| max_upload_size | |
| id | 1615638 |
| size | 53,987 |
dirgrab is a simple command-line tool to grab the contents of files within a directory and concatenate them, suitable for feeding whole-project contexts into language models.
It uses Git context when available (git ls-files) to only include tracked files (respecting .gitignore), but also works seamlessly on plain directories. By default, it includes a directory structure overview and file content headers.
Features:
-o), or the clipboard (-c).git ls-files in Git repositories (respects .gitignore by default).-u).-e) using .gitignore glob syntax.dirgrab.txt by default (override with --include-default-output).--no-tree).--- FILE: path/to/file ---) by default (disable with --no-headers).--no-pdf).-s, --stats).--no-git).dirgrab-lib).Ensure you have Rust and Cargo installed. Then, install dirgrab using Cargo:
cargo install dirgrab
# Or, to install/update from a local checkout:
# cargo install --path .
Verify the installation:
dirgrab --version
dirgrab [OPTIONS] [TARGET_PATH]
Arguments:
[TARGET_PATH]: Optional path to the directory or Git repository to process. Defaults to the current working directory.Options:
-o, --output [FILE]: Write output to a file. Defaults to dirgrab.txt in the current directory if FILE is omitted. Conflicts with -c.-c, --clipboard: Copy output to the system clipboard. Conflicts with -o.--no-headers: Disable the default '--- FILE: ... ---' headers.--no-tree: Disable the default inclusion of the directory structure overview.-e, --exclude <PATTERN>: Add glob patterns to exclude files/dirs (can be used multiple times).-u, --include-untracked: [Git Mode Only] Include untracked files (still respects .gitignore and excludes). Has no effect if --no-git is used.--include-default-output: Include dirgrab.txt if it exists (overrides default exclusion).--no-git: Ignore Git context; treat target as a plain directory (disables .gitignore processing and the effect of -u).--no-pdf: Disable the default extraction of text content from PDF files.-s, --stats: Print output size (bytes) and word count to stderr upon completion.-v, -vv, -vvv: Increase verbosity level for logging (Warn, Info, Debug, Trace).-h, --help: Print help information.-V, --version: Print version information.Examples:
Grab tracked files from current Git repo to stdout (default tree and headers):
dirgrab
Grab files from current directory, disable tree and headers, output to file context.txt:
dirgrab --no-tree --no-headers -o context.txt
Grab tracked files, copy to clipboard, show stats:
dirgrab -c -s ../my-other-project/
Grab tracked + untracked files, excluding logs and build dirs, show stats:
dirgrab -u -e "*.log" -e "target/" -e "build/" -s
Grab all files from a non-Git directory, ignoring Git, excluding temp files, output to default dirgrab.txt:
dirgrab --no-git -e "*.tmp" /path/to/non-git-dir -o
Grab files, but force inclusion of dirgrab.txt if it exists:
dirgrab --include-default-output
--no-git is not used, dirgrab uses git ls-files to determine which files to include. This automatically respects .gitignore rules. The -u flag adds untracked files (still respecting .gitignore). User exclusions (-e) are applied. dirgrab.txt is excluded unless --include-default-output is used.--no-git or not a repo): dirgrab walks the directory tree. It includes all files found unless they match a user exclusion pattern (-e) or the default exclusion (dirgrab.txt, unless overridden). .gitignore files are ignored.--no-tree to disable this.--- FILE: <relative_path> ---. The path is relative to the Git repo root (in Git mode) or the target path (in non-Git mode). Use --no-headers to disable.dirgrab.txt is excluded by default to prevent accidental inclusion of previous runs. Use --include-default-output to override this specific exclusion.-o) Default: If -o is provided without a subsequent filename, the output is written to dirgrab.txt in the current working directory..pdf (case-insensitive). This relies on the pdf-extract crate and works best for text-based PDFs. Image-based PDFs or errors during extraction will result in a warning, and the file's content will be skipped (though a header might be added if enabled). Can be disabled with a feature flag.dirgrab attempts to read files as UTF-8. If a file cannot be decoded (likely binary), it is skipped, and a warning is printed to stderr (visible with -v).-s, --stats): If enabled, the total byte count and a simple word count (based on whitespace) of the final generated output (including tree and headers) are printed to stderr after the operation completes successfully.dirgrab-lib)The core logic is available as a separate library crate (dirgrab-lib) for use in other Rust projects. The library structure has been refactored for better maintainability. See its documentation on docs.rs (link will work after publishing).
Added
pdf-extract crate.-s, --stats flag to optionally print output byte size and word count to stderr.--no-git flag to force directory walking and ignore Git context even in a repository.--include-default-output flag to specifically override the default exclusion of dirgrab.txt.--no-tree flag to disable the directory tree overview (which is now enabled by default).Changed
--no-tree to disable. (Previously required --include-tree).-o/--output flag now defaults to writing to dirgrab.txt in the current directory if the flag is provided without an explicit filename.-s or --stats to enable. (Previously always printed).dirgrab.txt is now excluded by default in both Git and non-Git modes. Use --include-default-output to include it.Internal
dirgrab-lib into modules (config, errors, listing, processing, tree, utils) for better organization.ls-files) integration.-o <file>), or clipboard (-c).-e).--no-headers).-u).-v).This project is licensed under either of:
at your option.
Contributions are welcome! Please feel free to submit issues and pull requests. Discuss significant changes via an issue first. Ensure code adheres to existing style (checked by cargo fmt) and passes Clippy (cargo clippy) and tests (cargo test).