Code Monkey home page Code Monkey logo

mktree's Introduction

mktree

mktree is a simple tool for creating directory trees in one shot. It's somewhat similar to what you can do with mkdir and brace expansion, but with an easier syntax and better usability.

Installation

Arch users can simply run the following command from the project directory:

makepkg -si

Anyone else can use pip:

pip install --user mktree

Usage

mktree allows you to create complex directory trees with a simple syntax

 $ mktree -P this/is,a.bunch,of/directories
 .
 ├── this
 │   ├── is
 │   └── a
 ├── bunch
 └── of
     └── directories

Th -P flag makes sure we are given a preview of the directory tree without actually creating any directory. For a simpler list-like preview, use the -p flag instead. A confirmation prompt is also available by using the -i flag.

You can find a complete list of all the available options here.

Now let's take a look at the string we've passed as argument. Notice how the argument string is made up of directories names separated by one of these three special characters: /, , and ..

Let's start with a very basic example

$ mktree -P A
.
└── A

This will simply create a directory A inside the current directory.

What if you want to create a folder B inside the folder A?

$ mktree -P A/B
.
└── A
    └── B

That's the purpose of the / character: it tells mktree to create the following directories inside the previous one.

Now a little more advanced example

$ mktree -P A/B,C
.
└── A
    ├── B
    └── C

This will create the directories B and C inside the directory A. The , character tells mktree to create the following directory at the same level of the previous one.

Continuing the above example, suppose that after you type C you need to create a folder D at the same level of the folder A. Remember that you've used the / character to move one level down the directory tree and now you want go back. That's when the . character comes in: it tells mktree to create the following directories one level up the directory tree

$ mktree -P A/B,C.D
.
└── A
│   ├── B
│   └── C
└── D

You can use many . characters in sequence to move up multiple levels, but you won't be able to move outside the current working directory

$ mktree -P A/B/C,D..E/F...H
.
├─ A
│  └─ B
│     ├─ C
│     └─ D
├─ E
│  └─ F
└─ H

Since mktree can take many tree descriptions as arguments, to avoid using . multiple times in sequence to reach the root directory, you can simply start another argument. The above example can in fact be rewritten as:

$ mktree -P A/B/C,D E/F H
.
├─ A
│  └─ B
│     ├─ C
│     └─ D
├─ E
│  └─ F
└─ H

Note: you can escape . or , if you'll ever need to use them as part of a directory name:

$ mktree -P A\\,B,C
.
├─ A,B
└─ C

License

See LICENSE.txt.

mktree's People

Contributors

gcmt avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.