Page MenuHomeFreeBSD

D18790.id52689.diff
No OneTemporary

D18790.id52689.diff

Index: bin/sh/parser.c
===================================================================
--- bin/sh/parser.c
+++ bin/sh/parser.c
@@ -40,6 +40,8 @@
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
+#include <sys/param.h>
+#include <pwd.h>
#include <stdlib.h>
#include <unistd.h>
#include <stdio.h>
@@ -130,6 +132,7 @@
static void synerror(const char *) __dead2;
static void setprompt(int);
static int pgetc_linecont(void);
+static void getusername(char *, size_t);
static void *
@@ -1969,6 +1972,30 @@
return (c);
}
+
+static void
+getusername(char *name, size_t namelen)
+{
+ static char cached_name[MAXLOGNAME];
+ struct passwd *pw;
+ uid_t uid;
+
+ if (cached_name[0] == '\0') {
+ uid = getuid();
+ pw = getpwuid(uid);
+ if (pw != NULL) {
+ snprintf(cached_name, sizeof(cached_name),
+ "%s", pw->pw_name);
+ } else {
+ snprintf(cached_name, sizeof(cached_name),
+ "%u", uid);
+ }
+ }
+
+ snprintf(name, namelen, "%s", cached_name);
+}
+
+
/*
* called by editline -- any expansions to the prompt
* should be added here.
@@ -2024,6 +2051,17 @@
while ((ps[i] != '\0') && (ps[i] != trim))
i++;
--i;
+ break;
+
+ /*
+ * User name.
+ */
+ case 'u':
+ ps[i] = '\0';
+ getusername(&ps[i], PROMPTLEN - i);
+ /* Skip to end of username. */
+ while (ps[i + 1] != '\0')
+ i++;
break;
/*
Index: bin/sh/sh.1
===================================================================
--- bin/sh/sh.1
+++ bin/sh/sh.1
@@ -1402,6 +1402,8 @@
This system's fully-qualified hostname (FQDN).
.It Li \eh
This system's hostname.
+.It Li \eu
+User name.
.It Li \eW
The final component of the current working directory.
.It Li \ew
Index: share/skel/dot.shrc
===================================================================
--- share/skel/dot.shrc
+++ share/skel/dot.shrc
@@ -33,7 +33,7 @@
# set prompt: ``username@hostname:directory $ ''
-PS1="`whoami`@\h:\w \\$ "
+PS1="\u@\h:\w \\$ "
# search path for cd(1)
# CDPATH=:$HOME

File Metadata

Mime Type
text/plain
Expires
Sun, Aug 16, 1:40 AM (20 h, 45 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
36809341
Default Alt Text
D18790.id52689.diff (1 KB)

Event Timeline