Index: terminal.install
===================================================================
RCS file: /cvs/drupal/contributions/modules/terminal/terminal.install,v
retrieving revision 1.3.2.1
diff -u -r1.3.2.1 terminal.install
--- terminal.install	24 Nov 2009 23:06:41 -0000	1.3.2.1
+++ terminal.install	27 Nov 2009 23:12:59 -0000
@@ -55,12 +55,14 @@
 }
 
 /**
- * Add an ID column to the history table.
+ * Add an ID and timestamp column to the history table.
  */
 function terminal_update_6000() {
   $ret = array();
   $schema = terminal_schema();
   $new_field = $schema['terminal_history']['fields']['hid'];
   db_add_field($ret, 'terminal_history', 'hid', $new_field);
+  $new_field = $schema['terminal_history']['fields']['time'];
+  db_add_field($ret, 'terminal_history', 'time', $new_field); 
   return $ret;
 }
Index: terminal.api.php
===================================================================
RCS file: terminal.api.php
diff -N terminal.api.php
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ terminal.api.php	1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,24 @@
+<?php
+// $Id$
+
+/**
+ * Expose a method to be executed by the Drupal Terminal.
+ *
+ * @return
+ *   An array of terminal commands. Each command has one of the following items:
+ *   - "title": The name of the command.
+ *   - "pattern": Helpful pattern text that's displayed to the user when using
+ *     the 'help' command.
+ *   - "description": A short help text for the command.
+ *   - "callback": The function callback which is executed when the command is
+ *     run by the user.
+ */
+function hook_terminal() {
+  $commands['help'] = array(
+    'title' => t('Help'),
+    'pattern' => t('help [pattern]'),
+    'description' => t('Displays helpful information about builtin commands. If PATTERN is specified, gives detailed help on the command matching PATTERN.'),
+    'callback' => 'terminal_command_help',
+  );
+  return $commands;
+}
Index: terminal.terminal.inc
===================================================================
RCS file: terminal.terminal.inc
diff -N terminal.terminal.inc
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ terminal.terminal.inc	1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,62 @@
+<?php
+// $Id$
+
+/**
+ * Implementation of hook_terminal().
+ */
+function terminal_terminal() {
+  $commands['help'] = array(
+    'title' => t('Help'),
+    'pattern' => t('help [PATTERN]'),
+    'description' => t('Displays helpful information about builtin commands. If PATTERN is specified, gives detailed help on the command matching PATTERN.'),
+    'callback' => 'terminal_command_help',
+  );
+  $commands['history'] = array(
+    'title' => t('History'),
+    'pattern' => 'help [n]',
+    'description' => t('Display the history list. If N is provided, will display the given amount of results. Defaults to 5.'),
+    'callback' => 'terminal_command_history',
+  );
+  return $commands;
+}
+
+/**
+ * Terminal callback for "help".
+ */
+function terminal_command_help($args = array()) {
+  $commands = terminal_commands();
+  // Check if the user wants help on a certain command.
+  $name = isset($args[0]) ? $args[0] : -1;
+  if (isset($commands[$name])) {
+    $command = $commands[$name];
+    $title = isset($command['title']) ? $command['title'] : $name;
+    $description = isset($command['description']) ? $command['description'] : '';
+    $pattern = isset($command['pattern']) ? $command['pattern'] : $name;
+    echo "$title: $pattern\n $description";
+  }
+  else {
+    // Present information about all the available commands.
+    echo t("Drupal Terminal, version !version\nExecute 'help [command]' to retrieve more information about the given command:\n", array('!version' => '$Id$'));
+    echo implode(', ', array_keys($commands));
+  }
+}
+
+/**
+ * Terminal command for "history".
+ */
+function terminal_command_history($args = array()) {
+  global $user;
+  $n = (isset($args[0]) && is_numeric($args[0])) ? $args[0] : 5;
+  // Retrieve the user's history.
+  $result = db_query("SELECT * FROM {terminal_history} WHERE uid = %d ORDER BY hid DESC LIMIT 0,%d", $user->uid, $n);
+  // Construct the history array.
+  $hist = array();
+  while ($history = db_fetch_object($result)) {
+    $hist[$history->hid] = $history->input;
+  }
+  // Make sure to present it in the correct order.
+  ksort($hist);
+  foreach ($hist as $input) {
+    echo $input . "\n";
+  }
+}
