fixup! mingw: Support git_terminal_prompt with more terminals

Reduce shell invocations by chaining commands together.

Use 'echo' instead of 'printf \\n'.

Use 'read -s' instead of 'stty [-]echo', because we don't have 'stty'
in old msysgit.

Use 'bash' instead of 'sh' as 'read -s' is bash-specific (in case we
ever switch to dash or some other POSIX-only shell).

Signed-off-by: Karsten Blees <blees@dcon.de>
This commit is contained in:
Karsten Blees
2015-05-08 23:40:29 +02:00
parent 03a9c6649b
commit 297b780dc8

View File

@@ -97,20 +97,16 @@ static int disable_echo(void)
static char *xterm_prompt(const char *prompt, int echo)
{
const char *read_input[] = {
"sh", "-c",
"cat >/dev/tty && read -r line </dev/tty && echo \"$line\"",
/* Note: call 'bash' explicitly, as 'read -s' is bash-specific */
"bash", "-c", echo ?
"cat >/dev/tty && read -r line </dev/tty && echo \"$line\"" :
"cat >/dev/tty && read -r -s line </dev/tty && echo \"$line\" && echo >/dev/tty",
NULL
};
const char *echo_off[] = { "sh", "-c", "stty -echo </dev/tty", NULL };
const char *echo_on[] = { "sh", "-c", "stty echo </dev/tty", NULL };
const char *new_line[] = { "sh", "-c", "printf '\\n' >/dev/tty", NULL };
struct child_process child = CHILD_PROCESS_INIT;
static struct strbuf buffer = STRBUF_INIT;
int prompt_len = strlen(prompt), len = -1, code;
if (!echo && run_command_v_opt(echo_off, 0))
warning("Could not disable echo on xterm");
child.argv = read_input;
child.in = -1;
child.out = -1;
@@ -143,12 +139,6 @@ ret:
if (!code)
finish_command(&child);
if (!echo) {
if (run_command_v_opt(echo_on, 0))
warning("Could not enable echo on xterm");
run_command_v_opt(new_line, 0);
}
return len < 0 ? NULL : buffer.buf;
}