Index: src/test/org/codehaus/groovy/tools/shell/commands/RegisterCommandTest.groovy
===================================================================
--- src/test/org/codehaus/groovy/tools/shell/commands/RegisterCommandTest.groovy	(revision 0)
+++ src/test/org/codehaus/groovy/tools/shell/commands/RegisterCommandTest.groovy	(revision 0)
@@ -0,0 +1,75 @@
+/*
+ * Copyright 2003-2007 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.codehaus.groovy.tools.shell.commands
+
+import org.codehaus.groovy.tools.shell.CommandException
+import org.codehaus.groovy.tools.shell.CommandSupport
+import org.codehaus.groovy.tools.shell.Shell
+
+/**
+ * Tests for the     {@link RegisterCommand}     class.
+ *
+ * @version $Id: AliasCommandTest.groovy 8447 2007-10-07 10:17:11Z user57 $
+ * @author <a href="mailto:chris@wensel.net">Chris K Wensel</a>
+ */
+class RegisterCommandTest
+extends CommandTestSupport {
+
+    void testRegister() {
+        shell << 'register org.codehaus.groovy.tools.shell.commands.EchoCommand'
+    }
+
+    void testRegisterDupes() {
+        shell << 'register org.codehaus.groovy.tools.shell.commands.EchoCommand'
+        shell << 'register org.codehaus.groovy.tools.shell.commands.EchoCommand echo2 \\e2'
+    }
+
+    void testRegisterDupesFail() {
+        try {
+            shell << 'register org.codehaus.groovy.tools.shell.commands.EchoCommand'
+            shell << 'register org.codehaus.groovy.tools.shell.commands.EchoCommand'
+            fail()
+        }
+        catch (CommandException expected) {}
+    }
+
+    void testRegisterFail() {
+        try {
+            shell << 'register'
+            fail()
+        }
+        catch (CommandException expected) {}
+    }
+}
+
+class EchoCommand
+extends CommandSupport {
+
+    EchoCommand(final Shell shell, final String name, final String alias) {
+        super(shell, name, alias)
+    }
+
+    EchoCommand(final Shell shell) {
+        super(shell, 'echo', '\\ec')
+    }
+
+    Object execute(final List args) {
+        io.out.println(args.join(' ')) //  TODO: i18n
+    }
+}
+
+
Index: src/test/org/codehaus/groovy/tools/shell/commands/EchoCommand.properties
===================================================================
--- src/test/org/codehaus/groovy/tools/shell/commands/EchoCommand.properties	(revision 12055)
+++ src/test/org/codehaus/groovy/tools/shell/commands/EchoCommand.properties	(working copy)
@@ -18,7 +18,7 @@
 # $Id$
 #
 
-command.description=Create an alias
-command.usage=
-command.help=Create an alias.
+command.description=Echo the args
+command.usage=<args>
+command.help=Echo the args.
 
Index: src/main/org/codehaus/groovy/tools/shell/commands.xml
===================================================================
--- src/main/org/codehaus/groovy/tools/shell/commands.xml	(revision 12100)
+++ src/main/org/codehaus/groovy/tools/shell/commands.xml	(working copy)
@@ -19,35 +19,37 @@
 
 <commands>
     <command>org.codehaus.groovy.tools.shell.commands.HelpCommand</command>
-    
+
     <command>org.codehaus.groovy.tools.shell.commands.ExitCommand</command>
-    
+
     <command>org.codehaus.groovy.tools.shell.commands.ImportCommand</command>
-    
+
     <command>org.codehaus.groovy.tools.shell.commands.DisplayCommand</command>
-    
+
     <command>org.codehaus.groovy.tools.shell.commands.ClearCommand</command>
-    
+
     <command>org.codehaus.groovy.tools.shell.commands.ShowCommand</command>
-    
+
     <command>org.codehaus.groovy.tools.shell.commands.InspectCommand</command>
-    
+
     <command>org.codehaus.groovy.tools.shell.commands.PurgeCommand</command>
-    
+
     <command>org.codehaus.groovy.tools.shell.commands.EditCommand</command>
-    
+
     <command>org.codehaus.groovy.tools.shell.commands.LoadCommand</command>
-    
+
     <command>org.codehaus.groovy.tools.shell.commands.SaveCommand</command>
 
     <command>org.codehaus.groovy.tools.shell.commands.RecordCommand</command>
 
     <command>org.codehaus.groovy.tools.shell.commands.HistoryCommand</command>
-    
+
     <command>org.codehaus.groovy.tools.shell.commands.AliasCommand</command>
-    
+
     <command>org.codehaus.groovy.tools.shell.commands.SetCommand</command>
+
+    <command>org.codehaus.groovy.tools.shell.commands.ShadowCommand</command>
     
-    <command>org.codehaus.groovy.tools.shell.commands.ShadowCommand</command>
+    <command>org.codehaus.groovy.tools.shell.commands.RegisterCommand</command>
 </commands>
 
Index: src/main/org/codehaus/groovy/tools/shell/commands/RegisterCommand.groovy
===================================================================
--- src/main/org/codehaus/groovy/tools/shell/commands/RegisterCommand.groovy	(revision 0)
+++ src/main/org/codehaus/groovy/tools/shell/commands/RegisterCommand.groovy	(revision 0)
@@ -0,0 +1,74 @@
+/*
+ * Copyright 2003-2007 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.codehaus.groovy.tools.shell.commands
+
+import org.codehaus.groovy.tools.shell.CommandSupport
+import org.codehaus.groovy.tools.shell.Shell
+import org.codehaus.groovy.tools.shell.Command
+
+/**
+ * The 'register' command.
+ *
+ * @version $Id: PurgeCommand.groovy 8449 2007-10-07 10:18:00Z user57 $
+ * @author <a href="mailto:chris@wensel.net">Chris K Wensel</a>
+ */
+class RegisterCommand
+extends CommandSupport {
+
+    RegisterCommand(final Shell shell) {
+        super(shell, "register", "\\rc")
+    }
+
+    public Object execute(List args) {
+        assert args != null
+
+        if (args.size() < 1) {
+            fail("Command 'register' requires at least 1 arguments") // TODO: i18n
+        }
+
+        String classname = args.get(0)
+
+        Class type = shell.getClassLoader().loadClass(classname)
+
+        Command command = null;
+
+        if (args.size() == 1)                   // use default name
+            command = type.newInstance(shell)
+        else if (args.size() == 2)              // pass name to ctor
+            command = type.newInstance(shell, args.get(1), null)
+        else if (args.size() == 3)              // pass name, alias to ctor
+            command = type.newInstance(shell, args.get(1), args.get(2))
+
+        def oldcommand = registry[command.name] // let's prevent collisions
+
+        if (oldcommand) {
+            fail("Can not rebind command: ${command.name}") // TODO: i18n
+        }
+
+        if (log.debugEnabled) {
+            log.debug("Created command '${command.name}': $command")
+        }
+
+        command = shell << command
+
+        if (shell.runner) {
+            shell.runner.completor << command
+        }
+
+    }
+
+}
\ No newline at end of file
Index: src/main/org/codehaus/groovy/tools/shell/commands/RegisterCommand.properties
===================================================================
--- src/main/org/codehaus/groovy/tools/shell/commands/RegisterCommand.properties	(revision 12055)
+++ src/main/org/codehaus/groovy/tools/shell/commands/RegisterCommand.properties	(working copy)
@@ -18,7 +18,7 @@
 # $Id$
 #
 
-command.description=Create an alias
-command.usage=
-command.help=Create an alias.
+command.description=Registers a new command with the shell
+command.usage=<classname> [<name>] [alias]
+command.help=Registers the given @|BOLD classname| as a new command.
 
Index: src/main/org/codehaus/groovy/tools/shell/Groovysh.groovy
===================================================================
--- src/main/org/codehaus/groovy/tools/shell/Groovysh.groovy	(revision 12100)
+++ src/main/org/codehaus/groovy/tools/shell/Groovysh.groovy	(working copy)
@@ -43,31 +43,31 @@
     extends Shell
 {
     private static final String NEWLINE = System.properties['line.separator']
-    
+
     private static final MessageSource messages = new MessageSource(Groovysh.class)
 
     private final BufferManager buffers = new BufferManager()
 
     private final GroovyShell interp
-    
+
     private final List imports = []
-    
+
     private InteractiveShellRunner runner
-    
+
     private History history
-    
+
     Groovysh(final ClassLoader classLoader, final Binding binding, final IO io) {
         super(io)
-        
+
         assert classLoader
         assert binding
-        
+
         interp = new GroovyShell(classLoader, binding)
 
         //
         // TODO: Change this to be more embed/test friendly
         //
-        
+
         def registrar = new XmlCommandRegistrar(this, classLoader)
         registrar.register(getClass().getResource('commands.xml'))
     }
@@ -79,11 +79,15 @@
     Groovysh(final IO io) {
         this(new Binding(), io)
     }
-    
+
     Groovysh() {
         this(new IO())
     }
 
+    ClassLoader getClassLoader() {
+        return interp.getClassLoader();
+    }
+
     //
     // Execution
     //
@@ -93,7 +97,7 @@
      */
     Object execute(final String line) {
         assert line != null
-        
+
         // Ignore empty lines
         if (line.trim().size() == 0) {
             return null
@@ -102,19 +106,19 @@
         maybeRecordInput(line)
 
         def result
-        
+
         // First try normal command execution
         if (isExecutable(line)) {
             result = executeCommand(line)
-            
+
             // For commands, only set the last result when its non-null/true
             if (result) {
                 lastResult = result
             }
-            
+
             return result
         }
-        
+
         // Otherwise treat the line as Groovy
         def current = []
         current += buffers.current()
@@ -144,7 +148,7 @@
                 // Should never happen
                 throw new Error("Invalid parse status: $status.code")
         }
-        
+
         return result
     }
 
@@ -180,7 +184,7 @@
             // class a {               <--- is true here
             //    def b() {            <--- is false here :-(
             //
-            
+
             if (parser.errorCollector.errorCount > 1 || !parser.failedWithUnexpectedEOF()) {
                 //
                 // HACK: Super insane hack... if we detect a syntax error, but the last line of the
@@ -235,7 +239,7 @@
      */
     private Object evaluate(final List buffer) {
         assert buffer
-        
+
         log.debug("Evaluating buffer...")
 
         if (io.verbose) {
@@ -274,14 +278,14 @@
         }
         finally {
             def cache = interp.classLoader.classCache
-            
+
             // Remove the script class generated
             cache.remove(type?.name)
 
             // Remove the inline closures from the cache as well
             cache.remove('$_run_closure')
         }
-        
+
         return result
     }
 
@@ -293,7 +297,7 @@
 
         buffer.eachWithIndex { line, index ->
             def lineNum = formatLineNumber(index + 1)
-            
+
             io.out.println(" ${lineNum}@|bold >| $line")
         }
     }
@@ -332,9 +336,9 @@
 
     private void loadUserScript(final String filename) {
         assert filename
-        
+
         def file = new File(userStateDirectory, filename)
-        
+
         if (file.exists()) {
             def command = registry['load']
 
@@ -391,7 +395,7 @@
             record.recordError(cause)
         }
     }
-    
+
     //
     // Hooks
     //
