Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: use of ":" to prefix commands, some other updates for recent changes

...

  • No need for go command to execute buffer.
  • Rich cross-platform edit-line editing, history and completion thanks to JLine JLine2.
  • ANSI colors (prompt, exception traces, etc).
  • Simple, yet robust, command system with online help, user alias support and more.
  • User profile support

...

No Format
./bin/groovysh --help
usage: groovysh [options] [...]
  -C, --color[=FLAG]         Enable or disable use of ANSI colors
  -D, --define=NAME=VALUE    Define a system property
  -T, --terminal=TYPE        Specify the terminal TYPE to use
  -V, --version              Display the version
  -classpath                 Specify where to find the class files - must
                             be first argument
  -cp, --classpath           Aliases for '-classpath'
  -d, --debug                Enable debug output
  -h, --help                 Display this help message
  -q, --quiet                Suppress superfluous output
  -v, --verbose              Enable verbose output

...

Commands all have a name and a shortcut (which is something like \:h). Commands may also have some predefined system aliases. Users may also create their own aliases.

Recognized Commands

:help

Display the list of commands (and aliases) or the help text for specific command.

The Command List
No Format
groovy:000> :help

For information about Groovy, visit:
    http://groovy.codehaus.org

Available commands:
  :help      (\:h ) Display this help message
  ?          (\:? ) Alias to: :help
  :exit      (\:x ) Exit the shell
  :quit      (\:q ) Alias to: :exit
  import     (\:i ) Import a class into the namespace
  :display   (\:d ) Display the current buffer
  :clear     (\:c ) Clear the buffer and reset the prompt counter.
  :show      (\:S ) Show variables, classes or imports
  :inspect   (\:n ) Inspect a variable or the last result with the GUI object browser
  :purge     (\:p ) Purge variables, classes, imports or bufferspreferences
  :edit      (\:e ) Edit the current buffer
  :load      (\:l ) Load a file or URL into the buffer
  .          (\:. ) Alias to: :load
  :save      (\:s ) Save the current buffer to a file
  :record    (\:r ) Record the current session to a file
  :history   (\:H ) Display, manage and recall edit-line history
  :alias     (\:a ) Create an alias
  :set       (\:= ) Set (or list) preferences
  :register  (:rc) Registers a new command with the shell
  :doc       (:D ) Opens a browser window displaying the doc for the argument
For help on a specific command type:
    :help <command>command
Help for a Command

While in the interactive shell, you can ask for help for any command to get more details about its syntax or function. Here is an example of what happens when you ask for help for the help command:

No Format
groovy:000> :help :help

usage: help [<command>]

Display the list of commands or the help text for <command>.

:exit

Exit the shell.

This is the only way to exit the shell. Well, you can still CTRL-C, but the shell will complain about an abnormal shutdown of the JVM.

...

This command can be given at any time to add new imports.

:display

Display the contents of the current buffer.

...

No Format
groovy:000> class Foo {
groovy:001> def bar
groovy:002> def baz() {
groovy:003> display
 001> class Foo {
 002> def bar
 003> def baz() {

:clear

Clears the current buffer, resetting the prompt counter to 000. Can be used to recover from compilation errors.

:show

Show variables, classes or preferences or imports.

:show variables
No Format
groovy:000> show variables
Variables:
  _ = true
:show classes
:show imports
:show preferences
:show all

:inspect

Opens the GUI object browser to inspect a variable or the result of the last evaluation.

:purge

Purges objects from the shell.

:purge variables
:purge classes
:purge imports
:purge preferences
:purge all

:edit

Edit the current buffer in an external editor.

Currently only works on UNIX systems which have Edit requires the EDITOR environment variable to be set, or have configured the editor preference to be configured.

:load

Load one or more files (or urls) into the buffer.

:save

Saves the buffer's contents to a file.

:record

Record the current session to a file.

:record start
:record stop
:record status

:history

Display, manage and recall edit-line history.

:history show
:history recall
:history flush
:history clear

:alias

Create an alias.

:set

Set or list preferences.

:doc

Opens a browser window displaying the doc for the argument.

 

No Format
groovy:000> :doc java.util.List
http://docs.oracle.com/javase/1.7.0/docs/api/java/util/List.html
http://groovy.codehaus.org/groovy-jdk/java/util/List.html

 

 

Preferences

Some of aspects of groovysh behaviors can be customized by setting preferences. Preferences are set using the set command or the \= shortcut.

...

Tip
titleMac OS X

To use TextEdit, the default text editor on Mac OS X, configure:

No Format
:set editor /Applications/TextEdit.app/Contents/MacOS/TextEdit

Setting a Preference

No Format
:set verbosity DEBUG

Listing Preferences

To list the current set preferences (and their values):

No Format
:show preferences
Note
titleLimitation

At the moment, there is no way to list all of the known/available preferences to be set.

Clearing Preferences (

...

i.e. Resetting to Defaults)

No Format
:purge preferences

User Profile Scripts and State

...