Bonsai is a command-line interface (CLI) tool and Python library designed for working with directory structures in a clear, compact, and visual way. It allows users to generate directory trees, save them as JSON files, load them from JSON, and compute relative paths between directories. The name "Bonsai" reflects the tool's ability to take something complex, like a filesystem, and represent it in an organized and elegant manner.
-
Visualize Directory Trees: Generate and display the structure of directories with optional details like file permissions and file sizes.
-
Export to JSON: Save the directory tree structure as a JSON file for later use or sharing.
-
Load from JSON: Load a directory tree from a JSON file and visualize it.
-
Python API: Compute the relative path between two directories.
-
Relative Paths: Import Bonsai as a Python library for programmatic directory tree manipulation.
- Clone the repository:
git clone https://github.com/abhi-pixel1/bonsai.git- Install the tool using pip:
pip install .The Bonsai CLI includes the following commands:
Generates and displays the directory tree for a given directory.
bonsai tree [DIRECTORY_PATH] [OPTIONS]DIRECTORY_PATH: The directory for which the tree should be generated (required).
-
-p,--show-permissions: Include file permissions in the tree output. -
-s,--show-size: Include file sizes in the tree output.
bonsai tree ./my_directory -p -sSaves the directory tree structure of a given directory to a JSON file.
bonsai save-tree [DIRECTORY_PATH] [OUTPUT_FILE]DIRECTORY_PATH: The directory for which the tree should be saved (required).OUTPUT_FILE: The file where the JSON output should be saved. Must have a .json extension.
bonsai save-tree ./my_directory tree.jsonLoads a directory tree structure from a JSON file and displays it.
bonsai jtree [JSON_FILE] [OPTIONS]JSON_FILE: Path to the JSON file containing the directory tree structure (required).
-p,--show-permissions: Include file permissions in the tree output.-s,--show-size: Include file sizes in the tree output.
bonsai jtree tree.json -p -sCalculates and displays the relative path between two directories.
bonsai relative [DESTINATION_PATH] [BASE_PATH]DESTINATION_PATH: The target directory.BASE_PATH: The starting directory.
bonsai relative ./my_directory ./another_directoryBonsai can also be used as a Python library to generate and visualize directory trees programmatically.
from bonsai import generate_directory_tree, visualize_treefrom bonsai import generate_directory_tree
tree = generate_directory_tree("./my_directory")
print(tree)from bonsai import visualize_tree
print(visualize_tree(tree, show_permissions=True, show_size=True))This project is licensed under the MIT License. See the LICENSE file for details.