From bd83eb93bfc855ce30e0c21c829c92cba1b4c04b Mon Sep 17 00:00:00 2001 From: Smasty Date: Sun, 24 Jun 2012 12:14:13 +0300 Subject: [PATCH 1/2] ConsoleIO::askAndHideAnswer - added support for zsh, ksh and csh shells. --- src/Composer/IO/ConsoleIO.php | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/Composer/IO/ConsoleIO.php b/src/Composer/IO/ConsoleIO.php index 08872baf7..1cc0fc1cf 100644 --- a/src/Composer/IO/ConsoleIO.php +++ b/src/Composer/IO/ConsoleIO.php @@ -162,10 +162,18 @@ class ConsoleIO implements IOInterface return $value; } - // handle other OSs with bash if available to hide the answer - if ('OK' === rtrim(shell_exec("/usr/bin/env bash -c 'echo OK'"))) { + // handle other OSs with bash/zsh/ksh/csh if available to hide the answer + $test = "/usr/bin/env %s -c 'echo OK' 2> /dev/null"; + foreach(array('bash', 'zsh', 'ksh', 'csh') as $sh){ + if('OK' === rtrim(shell_exec(sprintf($test, $sh)))){ + $shell = $sh; + break; + } + } + if(isset($shell)){ $this->write($question, false); - $command = "/usr/bin/env bash -c 'read -s mypassword && echo \$mypassword'"; + $readCmd = ($shell === 'csh') ? 'set mypassword = $<' : 'read mypassword'; + $command = sprintf("/usr/bin/env %s -c 'stty -echo; %s; stty echo; echo \$mypassword'", $shell, $readCmd); $value = rtrim(shell_exec($command)); $this->write(''); From 58f0d4aeaca39e37da0199f4b10403c83fee7b9f Mon Sep 17 00:00:00 2001 From: Smasty Date: Sun, 24 Jun 2012 13:00:35 +0300 Subject: [PATCH 2/2] fix CS --- src/Composer/IO/ConsoleIO.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Composer/IO/ConsoleIO.php b/src/Composer/IO/ConsoleIO.php index 1cc0fc1cf..b6adc02db 100644 --- a/src/Composer/IO/ConsoleIO.php +++ b/src/Composer/IO/ConsoleIO.php @@ -164,13 +164,13 @@ class ConsoleIO implements IOInterface // handle other OSs with bash/zsh/ksh/csh if available to hide the answer $test = "/usr/bin/env %s -c 'echo OK' 2> /dev/null"; - foreach(array('bash', 'zsh', 'ksh', 'csh') as $sh){ - if('OK' === rtrim(shell_exec(sprintf($test, $sh)))){ + foreach (array('bash', 'zsh', 'ksh', 'csh') as $sh) { + if ('OK' === rtrim(shell_exec(sprintf($test, $sh)))) { $shell = $sh; break; } } - if(isset($shell)){ + if (isset($shell)) { $this->write($question, false); $readCmd = ($shell === 'csh') ? 'set mypassword = $<' : 'read mypassword'; $command = sprintf("/usr/bin/env %s -c 'stty -echo; %s; stty echo; echo \$mypassword'", $shell, $readCmd);