Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

A simple tool for creating full directory trees in one shot

branch: master

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 smash
Octocat-spinner-32 .gitignore
Octocat-spinner-32 LICENSE.txt
Octocat-spinner-32 MANIFEST.in
Octocat-spinner-32 README.rst
Octocat-spinner-32 run_smash.py
Octocat-spinner-32 setup.py
Octocat-spinner-32 test_smash.py
README.rst

Smash

v0.2.1

Smash is a simple tool for creating full directory trees in one shot. This is somewhat similar to what the mkdir unix command can do, but with an easier syntax and better usability.

Installation

Install with pip:

$ pip install smash

with the usual:

$ python setup.py install

Usage

Smash is very easy to use. You just give a plain string made up of directories names and some special characters:

$ smash -p this:is+a]bunch+of:directories

and here what you get:

.
├── this
│   ├── is
│   └── a
├── bunch
└── of
    └── directories

The output above is going to be the directory tree generated by Smash. However, the directories are not yet created; in fact, we have specified a special -p (--preview) argument that tells Smash to show us all the directories that could be created with the given string. Remove it and smash will really create all those directories.

Now let's take a look at the string we've passed as argument. You noticed the string is made up of directories names separated by one of these three special characters: :, + and ]. Let's start with a very basic example:

$ smash -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?:

$ smash -p A:B
.
└── A
    └── B

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

Now a little more advanced example:

$ smash -p A:B+C
.
└── A
    ├── B
    └── C

This will create the directories B and C inside the directory A. The + character tells Smash 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 F at the same level of the folder A. Remeber that you've used the : character to move one level down the directory tree and now you want go back. That's the situation when the ] character comes in: it tells Smash to create the following directories one level up the directory tree:

$ smash -p A:B+C]F
.
└── A
│   ├── B
│   └── C
└── F

To better understand these special characters you may think of them as movements up and down the directory tree, as you type.

The ] character deserves a better clarification. Although you can type it as much as you can, there is a limit to how up you can go in the directory tree and that's the directory from where you are executing Smash.

Note: you don't have to be in a clean directory to execute Smash but be aware that it will not overwrite any directory if it already exists. Moreover, if a folder lacks of writings permissions Smash will simply ignore the error.

Save directory trees for future reuse

Smash allows to save directory trees for future reuse:

$ smash -s myproject project:tests+bin+src

The command above saves the specified directory tree with the name myproject (it is not created yet). Later you can create this directory tree with the following command:

$ smash -l myproject

Note that you can still use the -p (--preview) option to get a preview of the directory tree or even the -s (--save) option to save the directory tree with a different name (a copy is made):

$ smash -l myproject -s newproject

To view all the saved directory trees use the -a (--all) option:

$ smash -a
myproject: project:tests+bin+src
newproject: project:tests+bin+src

Too remove a specific saved directory tree use the -r (--remove) option:

$ smash -r myproject

I'll go on my own

Smash by default use the characters :, + and ] as 'movements'. They have no special meaning and are just a preference of the author. If you want to use your own preferred characters, just use the special option --movements specifying three characters separated by commas. Here an example:

$ smash --movements=@,^,] a@b^c]d

Take particular care to the order of the characters. The first character will replace the : character, the second character will replace the + one and the third character will replace the ] character. If you mess up this order the result won't be what you expected.

Be careful, depending on your shell some characters carry on a special meaning and could be interpreted by the shell. In that case wrap arguments with " characters.

What Smash accepts as input

Let's see some simple rules of what you can (and cannot) pass as argument to smash:

  • a string whose leading and trailing characters are :, + or ] won't be accepted:

    $ smash +a:b+c    # BAD!
    
  • a string filled with repetitions of :, + or ] mixed together won't be accepted. The only exception is the ] character: Smash allows to insert any repetition of it:

    $ smash a:b+]c    # BAD!
    
    $ smash +a:b]]c   # OK!
    
  • if you provide the --movements option with your custom characters, the rules above will apply to your custom characters and not to the original ones.

Command line options

Here all the available command line options ad their meanings:

  • -p | --preview: to show a preview of the directory tree it is going to be created with the given input.
  • -v | --verbose: to give a feedback of what has been created and what failed.
  • -s <name> | --save <name>: to save the current specified directory tree as <name>.
  • -l <name> | --load <name>: to use a previously saved directory tree named <name>.
  • -r <name> | --remove <name>: to remove a previously saved directory tree named <name>.
  • -a | --all: to list all saved directory trees.
  • --movements=<c1>,<c2>,<c3>: to use your own movements characters.
  • -c | --colors: to enable colored output.

Changelog

  • v0.2.1: fixed bug: error message when the ".smash" folder does not exist yet in the home directory.
  • v0.2.0: added save, load, remove and list directory trees functionalities. --colors option now takes no argument.
  • v0.1.1: colored output can be now enabled/diasbled. In preview, already existent folders are emphasized.
  • v0.1.0: first stable release
Something went wrong with that request. Please try again.