OSDN Git Service

add 'history' command
authorscribu <mail@scribu.net>
Wed, 3 Apr 2013 21:10:14 +0000 (00:10 +0300)
committerscribu <mail@scribu.net>
Wed, 3 Apr 2013 21:10:14 +0000 (00:10 +0300)
php/commands/shell.php

index 2cdcecb..3f0eac0 100644 (file)
@@ -13,8 +13,16 @@ class Shell_Command extends \WP_CLI_Command {
                while ( true ) {
                        $line = self::prompt();
 
-                       if ( '' === $line )
-                               continue;
+                       switch ( $line ) {
+                               case '': {
+                                       continue 2;
+                               }
+
+                               case 'history': {
+                                       self::print_history();
+                                       continue 2;
+                               }
+                       }
 
                        $line = rtrim( $line, ';' ) . ';';
 
@@ -79,6 +87,24 @@ BASH;
                return '/bin/bash -c ' . escapeshellarg( $cmd );
        }
 
+       private static function print_history() {
+               $history_file = self::get_history_path();
+
+               if ( !is_readable( $history_file ) )
+                       return;
+
+               $lines = array_filter( explode( "\n", file_get_contents( $history_file ) ) );
+
+               foreach ( $lines as $line ) {
+                       if ( 'history' == $line )
+                               continue;
+
+                       $line = rtrim( $line, ';' ) . ';';
+
+                       echo "$line\n";
+               }
+       }
+
        private static function get_history_path() {
                $data = getcwd() . get_current_user();