summaryrefslogtreecommitdiffstats
path: root/bin/csh/csh.c
diff options
context:
space:
mode:
authortb <tb@openbsd.org>2017-12-12 00:18:58 +0000
committertb <tb@openbsd.org>2017-12-12 00:18:58 +0000
commit0a9a54a35dd51b7f9951e810334b28bf33b99e6a (patch)
treea496a8bfe30774da4bc203f8d06781430cccd8fe /bin/csh/csh.c
parentThe code can be simplified by using clock_gettime(2)'s CLOCK_REALTIME (diff)
downloadwireguard-openbsd-0a9a54a35dd51b7f9951e810334b28bf33b99e6a.tar.xz
wireguard-openbsd-0a9a54a35dd51b7f9951e810334b28bf33b99e6a.zip
Include hostname in shell prompts by default
With tmux, ssh and vmd, we tend to open shells on many different hosts simultaneously and the default prompts '$ ' and '# ' for {,k}sh as well as '% ' and '# ' for csh become dangerous: it's very easy to issue a command on the wrong host. This can easily be avoided by displaying the hostname in the prompt. Everything beyond "hostname{$,#,%} " is going to be a matter of taste, so we left it at that. If you use an FQDN, only the first part (the output of 'hostname -s') will be printed. requested by and ok deraadt; mostly positive feedback many ok anton, brynet, bcallah and others
Diffstat (limited to 'bin/csh/csh.c')
-rw-r--r--bin/csh/csh.c15
1 files changed, 12 insertions, 3 deletions
diff --git a/bin/csh/csh.c b/bin/csh/csh.c
index 5df655ade5d..d737c31ab30 100644
--- a/bin/csh/csh.c
+++ b/bin/csh/csh.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: csh.c,v 1.41 2017/08/30 06:42:21 anton Exp $ */
+/* $OpenBSD: csh.c,v 1.42 2017/12/12 00:18:58 tb Exp $ */
/* $NetBSD: csh.c,v 1.14 1995/04/29 23:21:28 mycroft Exp $ */
/*-
@@ -401,7 +401,7 @@ main(int argc, char *argv[])
* Set up the prompt.
*/
if (prompt) {
- set(STRprompt, Strsave(uid == 0 ? STRsymhash : STRsymcent));
+ set(STRprompt, Strsave(uid == 0 ? STRpromptroot : STRpromptuser));
/* that's a meta-questionmark */
set(STRprompt2, Strsave(STRmquestion));
}
@@ -1283,7 +1283,16 @@ printprompt(void)
for (cp = value(STRprompt); *cp; cp++)
if (*cp == HIST)
(void) fprintf(cshout, "%d", eventno + 1);
- else {
+ else if (*cp == '%' && *(cp + 1) == 'm') {
+ char hostname[HOST_NAME_MAX + 1];
+ char *p;
+
+ gethostname(hostname, sizeof hostname);
+ if ((p = strchr(hostname, '.')) != NULL)
+ *p = '\0';
+ fprintf(cshout, "%s", hostname);
+ cp++;
+ } else {
if (*cp == '\\' && cp[1] == HIST)
cp++;
(void) vis_fputc(*cp | QUOTE, cshout);