Fix Command Prompt For Usernames With '$' In Them (#326)
Escaped $ character within variable strings used in PROMPT environment variable to distinguish them the special characters used by the PROMPT command.
This commit is contained in:
parent
ed70a1a7f8
commit
01adadc9e2
15
session.c
15
session.c
|
@ -466,8 +466,8 @@ static int
|
|||
setup_session_vars(Session* s)
|
||||
{
|
||||
wchar_t *pw_dir_w = NULL, *tmp = NULL;
|
||||
char buf[256];
|
||||
wchar_t wbuf[256];
|
||||
char buf[1024] = { 0 };
|
||||
wchar_t wbuf[1024] = { 0 };
|
||||
char *laddr, *c;
|
||||
int ret = -1;
|
||||
|
||||
|
@ -513,8 +513,15 @@ setup_session_vars(Session* s)
|
|||
SetEnvironmentVariableA("TERM", s->term);
|
||||
|
||||
if (!s->is_subsystem) {
|
||||
UTF8_TO_UTF16_WITH_CLEANUP(tmp, s->pw->pw_name);
|
||||
_snwprintf(wbuf, sizeof(wbuf)/2, L"%ls@%ls $P$G", tmp, _wgetenv(L"COMPUTERNAME"));
|
||||
_snprintf(buf, ARRAYSIZE(buf), "%s@%s", s->pw->pw_name, getenv("COMPUTERNAME"));
|
||||
UTF8_TO_UTF16_WITH_CLEANUP(tmp, buf);
|
||||
/* escape $ characters as $$ to distinguish from special prompt characters */
|
||||
for (int i = 0, j = 0; i < wcslen(tmp) && j < ARRAYSIZE(wbuf) - 1; i++) {
|
||||
wbuf[j] = tmp[i];
|
||||
if (wbuf[j++] == L'$')
|
||||
wbuf[j++] = L'$';
|
||||
}
|
||||
wcscat_s(wbuf, ARRAYSIZE(wbuf), L" $P$G");
|
||||
SetEnvironmentVariableW(L"PROMPT", wbuf);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue