@@ -77,17 +77,26 @@ static void restore_term(void)
77
77
hconin = INVALID_HANDLE_VALUE;
78
78
}
79
79
80
- static int disable_echo(void )
80
+ static int set_echo(int echo )
81
81
{
82
- hconin = CreateFile("CONIN$", GENERIC_READ | GENERIC_WRITE,
83
- FILE_SHARE_READ, NULL, OPEN_EXISTING,
84
- FILE_ATTRIBUTE_NORMAL, NULL);
82
+ DWORD new_cmode;
83
+
84
+ if (hconin == INVALID_HANDLE_VALUE)
85
+ hconin = CreateFile("CONIN$", GENERIC_READ | GENERIC_WRITE,
86
+ FILE_SHARE_READ, NULL, OPEN_EXISTING,
87
+ FILE_ATTRIBUTE_NORMAL, NULL);
85
88
if (hconin == INVALID_HANDLE_VALUE)
86
89
return -1;
87
90
88
91
GetConsoleMode(hconin, &cmode);
92
+ new_cmode = cmode | ENABLE_LINE_INPUT;
93
+ if (echo)
94
+ new_cmode |= ENABLE_ECHO_INPUT;
95
+ else
96
+ new_cmode &= ~ENABLE_ECHO_INPUT;
97
+
89
98
sigchain_push_common(restore_term_on_signal);
90
- if (!SetConsoleMode(hconin, cmode & (~ENABLE_ECHO_INPUT) )) {
99
+ if (!SetConsoleMode(hconin, new_cmode )) {
91
100
CloseHandle(hconin);
92
101
hconin = INVALID_HANDLE_VALUE;
93
102
return -1;
@@ -96,13 +105,20 @@ static int disable_echo(void)
96
105
return 0;
97
106
}
98
107
108
+ static int disable_echo(void)
109
+ {
110
+ return set_echo(0);
111
+ }
112
+
99
113
static char *shell_prompt(const char *prompt, int echo)
100
114
{
101
115
const char *read_input[] = {
102
116
/* Note: call 'bash' explicitly, as 'read -s' is bash-specific */
103
117
"bash", "-c", echo ?
104
- "cat >/dev/tty && read -r line </dev/tty && echo \"$line\"" :
105
- "cat >/dev/tty && read -r -s line </dev/tty && echo \"$line\" && echo >/dev/tty",
118
+ "test \"a$SHELL\" != \"a${SHELL%.exe}\" || exit 127; cat >/dev/tty &&"
119
+ " read -r line </dev/tty && echo \"$line\"" :
120
+ "test \"a$SHELL\" != \"a${SHELL%.exe}\" || exit 127; cat >/dev/tty &&"
121
+ " read -r -s line </dev/tty && echo \"$line\" && echo >/dev/tty",
106
122
NULL
107
123
};
108
124
struct child_process child = CHILD_PROCESS_INIT;
@@ -138,7 +154,10 @@ static char *shell_prompt(const char *prompt, int echo)
138
154
close(child.out);
139
155
code = finish_command(&child);
140
156
if (code) {
141
- error("failed to execute prompt script (exit code %d)", code);
157
+ if (code != 127)
158
+ error("failed to execute prompt script (exit code %d)",
159
+ code);
160
+
142
161
return NULL;
143
162
}
144
163
@@ -161,9 +180,11 @@ char *git_terminal_prompt(const char *prompt, int echo)
161
180
162
181
/* try shell_prompt first, fall back to CONIN/OUT if bash is missing */
163
182
char *result = shell_prompt(prompt, echo);
164
- if (result || errno != ENOENT )
183
+ if (result)
165
184
return result;
166
185
186
+ if (echo && set_echo(1))
187
+ return NULL;
167
188
#endif
168
189
169
190
input_fh = fopen(INPUT_PATH, "r" FORCE_TEXT);
0 commit comments