Bitbucket is a code hosting site with unlimited public and private repositories. We're also free for small teams!


A generic command interpreter with multicommand support.

The shnake library has been initially developped to correctly handle
PhpSploit framework's shell interfaces. That being said, it was built
in order to stand generic, and usable by any other open-source project.

- The shell part extends the pretty good 'cmd' standard library, adding many
new features, and a few new behaviors.

- The shnake lexer depends on the pyparsing library.

It was built to theorically work on all 3.x python versions.
For any bug, issue or enhancement proposal, please contact the author.

NOTE: Keep in mind that the shnake library extends and wraps the
      `cmd` python standard library. It means that you must read
      the `cmd` documentation, in order to correctly understand
      how shnake works, and its new features.


Mandatory dependencies::

Optional dependencies:

Tested with python3.4


Command line interface:
  * The command line interpreter has been highly enhanced, with a
    complete overwrite of the parseline() method, to provide the
    most bash-like features as possible.
  * Multi commands, separated by semicolons can now be typed.
  * Multi line command also can be written, like on bash prompt by
    ending a line with a backslash, prompting the user to continue
    writing the command in the next line (like bash's PS2).
  * Strings can now be enquoted, to be processed as a single argument.

Command execution:
  * An argv array of arguments is now passed as do_foo() argument
    (an all other *cmd related methods) instead of the 'cmd' tuple.
  * The interpret() method can be used to eval a string as a list of
    shnake commands. It also can be used inside do_* commands.

Prompt feature:
  * Included an input() wrapper (classe's raw_input() method) that
    makes use of regular expressions to automatically enclose
    enventual prompt's ANSI color codes with '\\01%s\\02', fixing
    readline's prompt length missinterpretation on colored ones.
  * Since multiline commands are supported, a new variable:
    prompt_ps2 can be used to change PS2 prompt prefix.
  * EOFError raised during input() are the same as sending the
    'exit' command to the interpreter.

Exception handling:
  * The new onexception() method has been made to handle exceptions.
    It eases a lot command methods (do_foo()) development, allowing
    them to simply raise exceptions on error, that will be
    automatically handled and represented by a standard error line.
  * An exception `foo` is dispatched to a method `except_foo` if
    available; the except_ method is passed a single argument, the
    exception object itself.
  * The new variable `error` defines the error line template.

Command return values:
  * Adding support for command return values. Instead of the 'cmd'
    trivial boolean behavior, any command are now able to return
    anything. The postcmd method manages integer return values, in
    a similar way than the sys.exit's behavior.
  * To leave the cmdloop() method, a SystemExit must be raised
    (with the exit() built_in function for example)

Misc behaviors:
  * Extended the get_names() method, which now can take an instance
    as argument, limiting the returned attributes to this one.
  * Unlike `cmd` lib, emptyline()'s default behavior defaultly does
    nothing instead of repeating the last typed command (bash like).
  * Typing 'EOF' to leave is not used on shnake, consider using
    'exit' and raise SystemExit instead.
  * The classe's default() method had been enhanced, writing command
    representation in case of unprintable chars, and also takes use of
    the new 'nocmd' variable.
  * When left, the cmdloop() methods acts exactly in the same way
    that command return values behavior, meaning that the return
    value will be an interger anyway, 0 in case of no error.

Limitations & Other changes:
  * Unlike 'cmd', the shnake library do not provides support for
    command line interpretation without input() built-in function.
  * Unlike 'cmd', shnake is NOT compatible with python 2.x.

Recent activity

Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.