Skip to main content

Convert text directory trees (struct.txt) into real folders and files.

Project description

๐Ÿ“˜ tree2cmd

Convert text-based directory trees into real folders and files.

PyPI Version Python Versions MIT License Tests 100% Platforms PyPI Downloads GitHub Tests Status Publish to TestPyPI Publish to PyPI Auto Version Bump


๐Ÿ“‘ Table of Contents


โœจ Overview

tree2cmd converts text-based directory trees (ASCII/Unicode) like:

Project/
โ”œโ”€โ”€ src/
โ”‚   โ””โ”€โ”€ main.py
โ””โ”€โ”€ README.md

into actual folders and files using shell commands:

mkdir -p "Project/"
mkdir -p "Project/src/"
touch "Project/src/main.py"
touch "Project/README.md"

Perfect for:

โœ” Rapid project scaffolding โœ” Teaching directory layouts โœ” DevOps automation โœ” Reproducible project templates โœ” Converting documentation examples into real directories

Fully tested across ASCII trees, Unicode trees, emoji trees, and mixed indentation styles.


๐Ÿš€ Quick Start

1. Make struct.txt:

Project/
  src/
    main.py
  README.md

2. Convert to commands:

tree2cmd struct.txt

3. Actually create them:

tree2cmd struct.txt --run

๐Ÿ“ฆ Installation

Stable release:

pip install tree2cmd

Latest development version:

pip install git+https://github.com/ajmanjoma/tree2cmd.git

๐Ÿ“‚ Example Input โ†’ Output

Input:

๐Ÿ“ฆ App/
  backend/
    api.py
  README.md

Output:

mkdir -p "๐Ÿ“ฆ App/"
mkdir -p "๐Ÿ“ฆ App/backend/"
touch "๐Ÿ“ฆ App/backend/api.py"
touch "๐Ÿ“ฆ App/README.md"

This works for any:

  • ASCII tree
  • Unicode tree
  • Emoji directory
  • Mixed indentation
  • Minimal struct format
  • Multi-root trees

๐Ÿ”ง Usage Guide

Dry run (recommended):

tree2cmd struct.txt

Execute commands:

tree2cmd struct.txt --run

Save script:

tree2cmd struct.txt --save setup.sh

Use standard input:

cat struct.txt | tree2cmd --stdin

Show tree instead of commands:

tree2cmd struct.txt --tree

Disable logs:

tree2cmd struct.txt --no-verbose

๐Ÿง  How It Works

tree2cmd uses a 3-stage pipeline:


1๏ธโƒฃ Parsing

Handles:

  • ASCII trees (|-, +--, etc.)
  • Unicode trees (โ”œโ”€โ”€, โ”‚, โ””โ”€โ”€)
  • Mixed whitespaces and unexpected characters
  • Emojis and non-ASCII folder names
  • Multi-root directories
  • Deep nesting

Uses indentation and tree symbols to infer hierarchy.


2๏ธโƒฃ Classification

Folder detection rules:

  • Ends with / โ†’ folder
  • Contains . โ†’ file
  • Next line is more indented โ†’ folder
  • Otherwise โ†’ file

3๏ธโƒฃ Command Generation

Folders โ†’ mkdir -p Files โ†’ touch

All paths:

  • Are normalized
  • Are quoted
  • Escape shell-sensitive characters

๐Ÿ“š Documentation

Topic File
Usage Guide docs/usage.md
CLI Options docs/cli.md
Parser Details docs/parser.md
API Reference docs/api.md
FAQ docs/faq.md
Contributing docs/contributing.md
Changelog docs/changelog.md

๐Ÿงช Running Tests

Run all tests:

python -m unittest discover -s tests -p "test*.py" -v

With Makefile:

make test

Coverage: 100% (parser + CLI)


๐Ÿ”„ Versioning & Publishing

1. Bump version automatically:

make version patch
# or minor / major

2. Build:

python -m build

3. Upload to PyPI:

twine upload dist/*

4. GitHub Actions (automatic):

  • On tag push โ†’ build + test + publish
  • On PR โ†’ run tests

Workflow located at:

.github/workflows/python-publish.yml

๐Ÿค Contributing

All contributions are welcome!

  1. Fork repo
  2. Create a branch
  3. Add tests for new features
  4. Run tests
  5. Open PR

See full guide: ๐Ÿ“„ docs/contributing.md


๐Ÿ—บ๏ธ Roadmap

  • Windows PowerShell support
  • JSON/YAML โ†’ tree converter
  • VSCode extension
  • GUI visualizer
  • Template engine (copy boilerplate files)

๐Ÿ“„ License

MIT License โ€” free for personal & commercial use.


๐Ÿ‘ค Author

Antony Joseph Mathew ๐Ÿ“ง antonyjosephmathew1@gmail.com ๐ŸŒ GitHub: https://github.com/ajmanjoma/tree2cmd

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

tree2cmd-0.2.4.tar.gz (14.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

tree2cmd-0.2.4-py3-none-any.whl (9.9 kB view details)

Uploaded Python 3

File details

Details for the file tree2cmd-0.2.4.tar.gz.

File metadata

  • Download URL: tree2cmd-0.2.4.tar.gz
  • Upload date:
  • Size: 14.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for tree2cmd-0.2.4.tar.gz
Algorithm Hash digest
SHA256 2b061fc1e1cdc2f1fd5a0716d195797a923a8c4480deabd7ede47c5f99a74daf
MD5 ade76ba238ba75a7ece9a8cd75175852
BLAKE2b-256 3ff5786742b0f29e0e9ae4f60bc989fc864479cb67e589f52257e0f14592a683

See more details on using hashes here.

Provenance

The following attestation bundles were made for tree2cmd-0.2.4.tar.gz:

Publisher: publish.yml on ajmanjoma/tree2cmd

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file tree2cmd-0.2.4-py3-none-any.whl.

File metadata

  • Download URL: tree2cmd-0.2.4-py3-none-any.whl
  • Upload date:
  • Size: 9.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for tree2cmd-0.2.4-py3-none-any.whl
Algorithm Hash digest
SHA256 6dfe0232d00a3b8052e5e3554694e183c66edab9cfd44a2a90437326f1ae82cf
MD5 612790ce866e35098f0859972e9c489b
BLAKE2b-256 bc73fe0cff7704e106bb9c5814b6c412563720e8e4c74eee0d1462bff6b6fa1f

See more details on using hashes here.

Provenance

The following attestation bundles were made for tree2cmd-0.2.4-py3-none-any.whl:

Publisher: publish.yml on ajmanjoma/tree2cmd

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page