Skip to content

Commit 297b780

Browse files
committed
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 <[email protected]>
1 parent 03a9c66 commit 297b780

File tree

1 file changed

+4
-14
lines changed

1 file changed

+4
-14
lines changed

compat/terminal.c

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -97,20 +97,16 @@ static int disable_echo(void)
9797
static char *xterm_prompt(const char *prompt, int echo)
9898
{
9999
const char *read_input[] = {
100-
"sh", "-c",
101-
"cat >/dev/tty && read -r line </dev/tty && echo \"$line\"",
100+
/* Note: call 'bash' explicitly, as 'read -s' is bash-specific */
101+
"bash", "-c", echo ?
102+
"cat >/dev/tty && read -r line </dev/tty && echo \"$line\"" :
103+
"cat >/dev/tty && read -r -s line </dev/tty && echo \"$line\" && echo >/dev/tty",
102104
NULL
103105
};
104-
const char *echo_off[] = { "sh", "-c", "stty -echo </dev/tty", NULL };
105-
const char *echo_on[] = { "sh", "-c", "stty echo </dev/tty", NULL };
106-
const char *new_line[] = { "sh", "-c", "printf '\\n' >/dev/tty", NULL };
107106
struct child_process child = CHILD_PROCESS_INIT;
108107
static struct strbuf buffer = STRBUF_INIT;
109108
int prompt_len = strlen(prompt), len = -1, code;
110109

111-
if (!echo && run_command_v_opt(echo_off, 0))
112-
warning("Could not disable echo on xterm");
113-
114110
child.argv = read_input;
115111
child.in = -1;
116112
child.out = -1;
@@ -143,12 +139,6 @@ static char *xterm_prompt(const char *prompt, int echo)
143139
if (!code)
144140
finish_command(&child);
145141

146-
if (!echo) {
147-
if (run_command_v_opt(echo_on, 0))
148-
warning("Could not enable echo on xterm");
149-
run_command_v_opt(new_line, 0);
150-
}
151-
152142
return len < 0 ? NULL : buffer.buf;
153143
}
154144

0 commit comments

Comments
 (0)