Changeset View
Changeset View
Standalone View
Standalone View
head/bin/sh/parser.c
Show First 20 Lines • Show All 1,972 Lines • ▼ Show 20 Lines | |||||
* called by editline -- any expansions to the prompt | * called by editline -- any expansions to the prompt | ||||
* should be added here. | * should be added here. | ||||
*/ | */ | ||||
char * | char * | ||||
getprompt(void *unused __unused) | getprompt(void *unused __unused) | ||||
{ | { | ||||
static char ps[PROMPTLEN]; | static char ps[PROMPTLEN]; | ||||
const char *fmt; | const char *fmt; | ||||
const char *home; | |||||
const char *pwd; | const char *pwd; | ||||
size_t homelen; | |||||
int i, trim; | int i, trim; | ||||
static char internal_error[] = "??"; | static char internal_error[] = "??"; | ||||
/* | /* | ||||
* Select prompt format. | * Select prompt format. | ||||
*/ | */ | ||||
switch (whichprompt) { | switch (whichprompt) { | ||||
case 0: | case 0: | ||||
▲ Show 20 Lines • Show All 44 Lines • ▼ Show 20 Lines | if (*fmt == '\\') | ||||
case 'w': | case 'w': | ||||
pwd = lookupvar("PWD"); | pwd = lookupvar("PWD"); | ||||
if (pwd == NULL || *pwd == '\0') | if (pwd == NULL || *pwd == '\0') | ||||
pwd = "?"; | pwd = "?"; | ||||
if (*fmt == 'W' && | if (*fmt == 'W' && | ||||
*pwd == '/' && pwd[1] != '\0') | *pwd == '/' && pwd[1] != '\0') | ||||
strlcpy(&ps[i], strrchr(pwd, '/') + 1, | strlcpy(&ps[i], strrchr(pwd, '/') + 1, | ||||
PROMPTLEN - i); | PROMPTLEN - i); | ||||
else | else { | ||||
home = lookupvar("HOME"); | |||||
if (home != NULL) | |||||
homelen = strlen(home); | |||||
if (home != NULL && | |||||
strcmp(home, "/") != 0 && | |||||
strncmp(pwd, home, homelen) == 0 && | |||||
(pwd[homelen] == '/' || | |||||
pwd[homelen] == '\0')) { | |||||
strlcpy(&ps[i], "~", | |||||
PROMPTLEN - i); | |||||
strlcpy(&ps[i + 1], | |||||
pwd + homelen, | |||||
PROMPTLEN - i - 1); | |||||
} else { | |||||
strlcpy(&ps[i], pwd, PROMPTLEN - i); | strlcpy(&ps[i], pwd, PROMPTLEN - i); | ||||
} | |||||
} | |||||
/* Skip to end of path. */ | /* Skip to end of path. */ | ||||
while (ps[i + 1] != '\0') | while (ps[i + 1] != '\0') | ||||
i++; | i++; | ||||
break; | break; | ||||
/* | /* | ||||
* Superuser status. | * Superuser status. | ||||
* | * | ||||
▲ Show 20 Lines • Show All 71 Lines • Show Last 20 Lines |