A CLI tool to generate a directory structure mapping.
Project description
Dirmapper
Dirmapper is a CLI tool to generate and create directory structures. It provides a visual representation of the directory and file structure, similar to the tree
command, with support for .gitignore
-like patterns to exclude specific files and directories. Additionally, it allows creating directory structures from templates.
Features
- Generate a hierarchical view of a directory structure.
- Create directory structures from templates.
- JSON Format
- YAML Format
- Create directory structures from a text file with the directory map/structure. Useful when asking ChatGPT to create you a project directory.
- Optionally create a reusable template from the directory map/structure.
- Support for
.mapping-ignore
file to exclude files and directories. - Optional integration with
.gitignore
to exclude patterns specified in.gitignore
. - Case-sensitive and case-insensitive sorting options.
- Support for various output styles and formats.
Installation
Using Homebrew
You can install dirmapper
using Homebrew:
brew tap nashdean/dirmap
brew install dirmapper
Using pipx
It is recommended to use pipx
to install dirmapper
in an isolated environment:
pipx install dirmapper
Using pip
You can also install dirmapper
using pip:
pip install dirmapper
Usage
Basic Usage
To generate a directory structure mapping:
dirmap read /path/to/root_directory /path/to/output_file
Writing Directory Structure from a Template
To create a directory structure from a template file (YAML or JSON):
dirmap write /path/to/template_file /path/to/root_directory
Writing Directory Structure from a Text File
To create a directory structure from a text file with the directory map/structure:
dirmap write /path/to/directory_map.txt /path/to/root_directory
Exclude Patterns with .mapping-ignore
Create a .mapping-ignore
file in the root directory and specify the patterns you want to exclude:
.git/
*.tmp
*.log
Then run:
dirmap read /path/to/root_directory /path/to/output_file --ignore_file /path/to/.mapping-ignore
Inline Ignores and Complex Regex in .mapping-ignore
You can now include complex regex patterns in your .mapping-ignore
file:
.git/
.*cache
regex:^.*\.log$
This file can be overridden by specifying your own .mapping-ignore file (named anything you want) using the flag specified earlier --ignore_file /path/to/.mapping-ignore
.
Disable .gitignore Integration
By default, dirmap
will also consider patterns in .gitignore
. To disable this feature:
dirmap read /path/to/root_directory /path/to/output_file --ignore_file /path/to/.mapping-ignore --no_gitignore
Case-Sensitive and Non-Case-Sensitive Sorting
You can specify the order in which directories and files are listed, with options for case-sensitive and non-case-sensitive sorting:
# Ascending order (case-insensitive)
dirmap read /path/to/root_directory /path/to/output_file --sort asc
# Ascending order (case-sensitive)
dirmap read /path/to/root_directory /path/to/output_file --sort asc:case
# Descending order (case-insensitive)
dirmap read /path/to/root_directory /path/to/output_file --sort desc
# Descending order (case-sensitive)
dirmap read /path/to/root_directory /path/to/output_file --sort desc:case
Show Version
To display the version of dirmapper
:
dirmap --version
or
dirmap -v
Specify Sorting Order
To generate a directory structure with ascending order:
dirmap /path/to/root_directory /path/to/output_file --sort asc
To generate a directory structure with descending order:
dirmap /path/to/root_directory /path/to/output_file --sort desc
Specify Output Style and Format
You can specify the style and format of the output using --style
and --format
options. Available styles include tree
, indentation
, flat_list
, markdown
, html
, and json
. Available formats include plain
, html
, and json
.
Example: HTML Style with HTML Format
dirmap /path/to/root_directory /path/to/output_file --style html --format html
Running All Styles with Their Respective Formats
mkdir -p ./style_outputs
dirmap . ./style_outputs/indentation_output.txt --sort asc --style indentation
dirmap . ./style_outputs/flat_list_output.txt --sort asc --style flat_list
dirmap . ./style_outputs/html_output.html --sort asc --style html --format html
dirmap . ./style_outputs/json_output.json --sort asc --style json --format json
dirmap . ./style_outputs/markdown_output.md --sort asc --style markdown
dirmap . ./style_outputs/tree_output.txt --sort asc --style tree
Example
Sample Directory Structure
project/
├── .git/
│ └── config
├── .github/
│ └── workflows/
│ └── ci.yml
├── src/
│ ├── main.py
│ ├── utils.py
└── README.md
Sample .mapping-ignore
.git/
.github/
Command
dirmap read project output.txt --ignore_file project/.mapping-ignore
Sample Output
project/
├── src/
│ ├── main.py
│ └── utils.py
└── README.md
Writing Directory Structure from Template
Sample Template (YAML)
meta:
version: "1.0"
tool: "dirmapper"
author: YOUR_NAME
template:
src:
project_name:
__init__.py: ""
tests:
__init__.py: ""
docs: {}
README.md: ""
setup.py: ""
requirements.txt: ""
.gitignore: ""
Command
dirmap write write_template.yaml directory
Sample Template (JSON)
{
"meta": {
"version": "1.0",
"tool": "dirmapper",
"author": "YOUR_NAME"
},
"template": {
"src": {
"project_name": {
"__init__.py": ""
}
},
"tests": {
"__init__.py": ""
},
"docs": {},
"README.md": "",
"setup.py": "",
"requirements.txt": "",
".gitignore": ""
}
}
Command
dirmap write write_template.json directory
Development
Running Tests
Tests are written using pytest
. To run the tests:
- Install the development dependencies:
pip install -e .[dev]
- Run the tests:
pytest
Troubleshooting
Homebrew
If you have previously tapped and installed the dirmapper package, here’s how you can uninstall and untap it:
- Uninstall the Package:
brew uninstall dirmapper
- Untap the Repository:
brew untap nashdean/dirmap
Contributing
Contributions are welcome! Please feel free to submit a pull request or open an issue on GitHub.
License
This project is licensed under the MIT License. See the LICENSE file for details.
Author
Nash Dean
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file dirmapper-1.0.7.tar.gz
.
File metadata
- Download URL: dirmapper-1.0.7.tar.gz
- Upload date:
- Size: 19.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.9.19
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 |
32853d77b8354b557d1b720ed3942fecfe099a15072595e9006f34187d3eef15
|
|
MD5 |
f92d153880dbbb8bfed62ea195cc0b25
|
|
BLAKE2b-256 |
169c1529165ef04464b62e23c02e22d7389fc1554215fcb7802826edad0f59d1
|
File details
Details for the file dirmapper-1.0.7-py3-none-any.whl
.
File metadata
- Download URL: dirmapper-1.0.7-py3-none-any.whl
- Upload date:
- Size: 19.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.9.19
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 |
fdf8de6544b1d36c889abf11dc4e6a54b9a1b311a8dba5e3d04fcd16bb94de1f
|
|
MD5 |
daa9114850bdb4eface1a02a274daeb0
|
|
BLAKE2b-256 |
87c320565724bf61df8415c95b767f4c29317555771d62516031ef56600d6997
|