From 274f1e26e1d4b9b62ddf7bec4094ba642d5284a7 Mon Sep 17 00:00:00 2001 From: scribu Date: Thu, 4 Apr 2013 01:54:56 +0300 Subject: [PATCH] compute the history file path at the beginning this avoids problems if the user calls chdir() --- php/commands/shell.php | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/php/commands/shell.php b/php/commands/shell.php index 3f0eac00..fd32cb6e 100644 --- a/php/commands/shell.php +++ b/php/commands/shell.php @@ -10,8 +10,10 @@ class Shell_Command extends \WP_CLI_Command { public function __invoke() { \WP_CLI::line( 'Type "exit" to close session.' ); + $this->set_history_file(); + while ( true ) { - $line = self::prompt(); + $line = $this->prompt(); switch ( $line ) { case '': { @@ -49,11 +51,11 @@ class Shell_Command extends \WP_CLI_Command { ) ); } - private static function prompt() { + private function prompt() { static $cmd; if ( !$cmd ) { - $cmd = self::create_prompt_cmd( 'wp> ', self::get_history_path() ); + $cmd = self::create_prompt_cmd( 'wp> ', $this->history_file ); } $fp = popen( $cmd, 'r' ); @@ -87,13 +89,11 @@ BASH; return '/bin/bash -c ' . escapeshellarg( $cmd ); } - private static function print_history() { - $history_file = self::get_history_path(); - - if ( !is_readable( $history_file ) ) + private function print_history() { + if ( !is_readable( $this->history_file ) ) return; - $lines = array_filter( explode( "\n", file_get_contents( $history_file ) ) ); + $lines = array_filter( explode( "\n", file_get_contents( $this->history_file ) ) ); foreach ( $lines as $line ) { if ( 'history' == $line ) @@ -105,10 +105,10 @@ BASH; } } - private static function get_history_path() { + private function set_history_file() { $data = getcwd() . get_current_user(); - return sys_get_temp_dir() . '/wp-cli-history-' . md5( $data ); + $this->history_file = sys_get_temp_dir() . '/wp-cli-history-' . md5( $data ); } private static function starts_with( $tokens, $line ) { -- 2.11.0