Skip to main content

KTrex

KTrex is an interactive terminal application for building directory and file structures. Point it at a folder, grow a tree with a few keystrokes, undo mistakes, save the layout, and reuse it later as a preset on any new project.

It runs as a curses TUI (tree on the left, actions on the right) and ships as a plain command line tool with no runtime dependencies.

Features

  • Interactive tree view with cursor navigation, expandable folders, and a mouse-wheel friendly viewport
  • In-app file preview (v) for any selected file, read-only, with scrolling and line numbers
  • Safe undo: a failed or reckless undo can never delete real data
  • Built-in presets for common project layouts (Python, Django, FastAPI, Flask, Go, Rust, Node, React, ML, static sites, and more)
  • Save the current tree to JSON and load it back later, or load a preset by name or file path
  • Presets and structures share one simple JSON format, so you can write your own
  • Everything stays inside the project root; symlinks are never followed
  • Works from the command line too: ktrex --apply python_package my-lib

Requirements

  • Python 3.10 or newer
  • A Unix-like terminal with curses (included in the standard library on Linux and macOS; Windows may need extra setup)

Install

pip install KTrex

Usage

Interactive session:

ktrex                # prompts for a directory
ktrex my-project     # create/open my-project
ktrex .              # work inside the current directory

Command line:

ktrex [directory] [--version] [--list-presets] [--apply PRESET]
ktrex --version
ktrex --list-presets
ktrex --apply python_package my-lib

Exit codes: 0 on success, 1 on an error (bad preset, unwritable directory).

Keyboard

Tree view (left pane):

Key Action
Up / Down Move the cursor
Right / Space Expand a folder
Left / Backspace Collapse a folder, or go to the parent
Enter Enter the selected folder
v Preview the selected file
PageUp / PageDown Move one page
Home / End Jump to the top or bottom
Mouse wheel Scroll the tree

Preview screen:

Key Action
Up / Down Scroll one line
PageUp / PageDown Scroll one page
Home / End Jump to the first or last visible page
ESC / q Close the preview and return to the tree

Menu and prompts (right pane and bottom line):

Key Action
Tab Switch focus between tree and menu
Up / Down Move the selection
Enter Run the highlighted action
ESC Cancel the current prompt or confirmation
ESC (main screen) Shows how to quit; it never exits on its own
y Confirm a pending confirmation

Quit from the menu (it asks for confirmation; ESC or anything except y cancels it).

File preview

Press v on a file to read it without leaving KTrex or opening an editor:

  • Header shows the filename and full path, clipped to the terminal width
  • Footer shows lines A-B/N, or N+ when the file was truncated by the limit
  • Empty files show a friendly note; binary files (containing NUL bytes) show a message instead of garbage; unreadable or missing files show the error
  • Symlinked files are not previewed, matching the tree's symlink policy
  • Reading is bounded: at most 256 KiB and 2000 lines are held in memory, so a huge file previews instantly and scrolling never rescans the disk
  • Preview is strictly read-only; it never touches the file or the undo history
  • The preview redraws from the current terminal size, so resizing mid-preview is safe

Presets

A preset describes a starting tree. KTrex ships twelve:

cli_tool, django_project, fastapi_project, flask_project, go_project,
ml_project, node_api, python_package, react_app, rust_project, static_site,
web_project

Use one from the command line:

ktrex --apply fastapi_project my-api

or from the TUI: choose Load Preset and type a preset name. To use your own preset, save it anywhere as a JSON file and enter its path in the same prompt:

Preset name or path: /home/me/presets/rust_cli.json

Preset format

One JSON object per entry. Every entry needs name and type; a dir may add children, which is a list of more entries. A file entry creates an empty file.

{
  "name": "project",
  "type": "dir",
  "children": [
    {
      "name": "src",
      "type": "dir",
      "children": [
        { "name": "main.py", "type": "file" }
      ]
    },
    { "name": "README.md", "type": "file" }
  ]
}

Rules:

  • name must be a single path segment (no slashes, no ., no ..)
  • type is "dir" or "file"
  • children only makes sense on "dir" entries
  • Applying a preset never overwrites anything that already exists; new entries are added to the tree and become undoable like any other creation

The same format is used by Save Structure and Load Structure, so a saved project layout is a preset you can edit by hand.

Safety

  • Existing files are never overwritten
  • Non-empty directories are never deleted
  • Undo only reverts entries KTrex created, and refuses if the file changed since creation
  • Every path is checked to stay inside the project root
  • Symbolic links are listed but never followed
  • Unreadable directories render as a note instead of crashing
  • A failed apply rolls back, keeping disk and undo history in sync

Development

git clone git@github.com:K2K22K2K22/KTrex.git
cd KTrex
python -m pip install -e .
python -m pytest

License

MIT License. See LICENSE.

Sponsor

If you find this project useful and want to support its development:

Buy Me a Monster

Metadata

Release files for KTrex 0.2.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for KTrex 0.2.5
File Size Uploaded
ktrex-0.2.5.tar.gz 24.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for KTrex 0.2.5
File Interpreter ABI Platform
ktrex-0.2.5-py3-none-any.whl Python 3 none any Details

Total release size: 45.5 kB

Release files / ktrex-0.2.5.tar.gz

Download URL ktrex-0.2.5.tar.gz
Size 24.5 kB
Tags Source
SHA-256 checksum
How to use checksums
8fffe308be91e8b7c7bc49a5b2923abd52a0ed7bc3df83aa997289ae5067bdc8
BLAKE2b-256 checksum
How to use checksums
a28b304ff148572611cd69113bc27b0c960af8c17ebf073bca2e668107f9db62
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.8

Release files / ktrex-0.2.5-py3-none-any.whl

Download URL ktrex-0.2.5-py3-none-any.whl
Size 21.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2d2e86b2ee23dd3ff7b317467e217c7eea5fc9086f15723cdd5008c12cf2dd4f
BLAKE2b-256 checksum
How to use checksums
86cfe9785e9ebe752e8e25dee3cf38631c287ed9c2f719b75f53c044e01fa89e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.8

Release history Release notifications | RSS feed

0.3.0

2 release files

This release

0.2.5 This release

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.69

2 release files

0.1.5

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page