Re: Include hostname in shell prompts by default

2017-12-09 Thread lists
Sat, 09 Dec 2017 12:33:30 -0700 "Theo de Raadt" 
> > Sat, 09 Dec 2017 12:02:07 -0700 "Theo de Raadt"   
> > > > With all the respect and understanding what you're saying is true, yet
> > > > I have the time to change my prompt, and it would still affect me.
> > > 
> > > If you have changed it, it is irrelevant what the value was before
> > > the change.  You detail no impact.  You appeal is 100% emotion.  
> > 
> > Hi Theo,
> > 
> > Anyone use Emacs tramp mode?  If it works after this change, I'm happy.
> > If not, I'd have to go and plea there, or plea here to have a tunable..
> > Over time tramp mode will pick it up, just as it picked up bash prompt.
> > Please don't let me get in the way of this change, objection retracted.  
> 
> OH COME ON
> 
> If you are noting the problem, then you probably use the software!
> 
> The diff is *trivial* to apply, and you could have tested that case
> before you replied, then provided definitive FACTUAL INFORMATION to
> the conversation instead of moaning and groaning all emo.
> 
> As I've told a few other people, this diff seperates the boys from the
> men.  The boys are the ones with 1 machine, maybe 2 with seperate
> keyboards.  The men are the ones with 50 machine or maybe even more,
> who are struggling with the time commitment to keep infrastructure on
> the leading tip, and therefore this totally minimal default prompt
> setting may be a substantial step at reducing error.
> 
> But maybe this boys vs men comparison also regards other
> conversational strategies, you ever think of that??
> 
> It is sub-conversations like this which cause many developers to not
> send their diffs to tech and move them forward more privately.  This
> forum has too many people who think their voice is equal when their
> discourse is sub-equal.  A big part of the project is a meritocratic
> which requires participants aim to keep the conversation about the
> TECHNICAL IMPACT rather than only 'gut reaction'.  Therefore many of
> you are not equal, because you don't attempt to be equal in discourse.
> You are 2 for 2 of saying essentially "maybe but maybe not" and taking
> no effort to elevate to FACTS.  Looking at my cat on the couch I see a
> clear look of "maybe but maybe not".  I think we can expect better on
> this list.

Hi Theo,

You'll find the boys cheering in the "+1" shell / modal editors section,
and also in the "-1" configuration management / cargo scripting section.

Please allow me to know (rarely say) what could affect "my" use case for
previous experience w/ Emacs tramp, not blaming this for withheld diffs.
After tests (debug), confirmed it WORKS without issues in this use case.

Trying this in use actually seems meaningful, and useful out of the box.
Now I have to invent another reason to keep setting PS1 on all machines:

PS1='\a=== \D{%a %b %d [%H:%M]} \u@\h:\w (\l) j\j e$? h\! ===\n\$ '

=== Sun Dec 10 [01:10] ant@sun:~ (tty00) j0 e0 h1 ===
$ 

I am not playing along the script, raised some concern here, that's all.
I'll run with this without any more fuss, just as if I didn't notice it.
As previously said, I'd retracted my objection already, confirmed again.

Kind regards,
Anton Lazarov



Re: Include hostname in shell prompts by default

2017-12-09 Thread Theo de Raadt
> But we should probably keep the POSIX default for sh.  POSIX doesn't
> cover csh, so we're free to do what we want here too.
> 
> So my proposal is to make the change, but stick with the current
> default for ksh-invoked-as-sh.

Seriously, can anyone find one reason other than "dusty papers"?




Re: Include hostname in shell prompts by default

2017-12-09 Thread Mark Kettenis
> From: "Theo de Raadt" 
> Date: Sat, 09 Dec 2017 11:38:44 -0700
> 
> > this just feels like a needless deviation.
> 
> all i can say is:
> 
> bash-4.4$ 

Which is perfectly fine for bash since it isn't the POSIX shell when
invoked as bash.  For the same reason we can do what we want for ksh.
But we should probably keep the POSIX default for sh.  POSIX doesn't
cover csh, so we're free to do what we want here too.

So my proposal is to make the change, but stick with the current
default for ksh-invoked-as-sh.




Re: Include hostname in shell prompts by default

2017-12-09 Thread Brian Callahan


On 12/9/2017 1:28 PM, Bryan Steele wrote:
> On Sat, Dec 09, 2017 at 06:44:44PM +0100, Theo Buehler wrote:
>> This was discussed in a smaller circle and has been in snaps for two
>> days, but I'd like to show this to a wider audience.
>>
>> Theo asked me to make sure that all our shells print a prompt including
>> the hostname by default. The reasoning is roughly as follows:
>>
>> 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.
>>
>> Since not everybody makes use of the config files in /etc/skel or runs
>> only login shells, it is not really possible to handle this with config
>> files. Thus, we decided to hardcode it in the shells. We are aware that
>> POSIX says that PS1 defaults to '$ ' or '# ' for sh(1).
>>
>> The simplest case is ksh: rely on the already existing shell escapes.
>> For sh we can easily fall back to these (the diff to ksh/lex.c).  For
>> csh, I decided to implement the "%m" prompt escape which is standard in
>> c-type shells, so I don't expect this to cause surprises.
>>
>> In single user mode and the early installer, gethostname() returns the
>> empty string, so the familiar prompts will be displayed there.
> I think we should go ahead with this for the reasons mentioned, the
> default configuration should make things easier for the people using it,
> which means developers doing release builds, spinning up vms, etc.
>
> People can go on and on about standards compliance, but if it means
> someone is less likely to reboot the wrong machine, or worse, then
> POSIX be damned.
>
> ok brynet@

I'm with brynet@ and the others on this. Was a nice surprise when I
installed a new snap last night, already proved itself to be useful.

ok bcallah@, fwiw

>> Index: bin/csh/const.c
>> ===
>> RCS file: /var/cvs/src/bin/csh/const.c,v
>> retrieving revision 1.8
>> diff -u -p -r1.8 const.c
>> --- bin/csh/const.c  26 Oct 2015 16:27:04 -  1.8
>> +++ bin/csh/const.c  8 Dec 2017 12:15:26 -
>> @@ -114,6 +114,8 @@ Char STRprintexitvalue[] = { 'p', 'r', '
>>  'a', 'l', 'u', 'e', '\0' };
>>  Char STRprompt[]= { 'p', 'r', 'o', 'm', 'p', 't', '\0' };
>>  Char STRprompt2[]   = { 'p', 'r', 'o', 'm', 'p', 't', '2', '\0' };
>> +Char STRpromptroot[]= { '%', 'm', '#', ' ', '\0' };
>> +Char STRpromptuser[]= { '%', 'm', '%', ' ', '\0' };
>>  Char STRpushdsilent[]   = { 'p', 'u', 's', 'h', 'd', 's', 'i', 'l', 
>> 'e', 'n',
>>  't', '\0' };
>>  Char STRret[]   = { '\n', '\0' };
>> @@ -138,8 +140,6 @@ Char STRspor2sp[]= { ' ', '|', '|', ' '
>>  Char STRsporsp[]= { ' ', '|', ' ', '\0' };
>>  Char STRstar[]  = { '*', '\0' };
>>  Char STRstatus[]= { 's', 't', 'a', 't', 'u', 's', '\0' };
>> -Char STRsymcent[]   = { '%', ' ', '\0' };
>> -Char STRsymhash[]   = { '#', ' ', '\0' };
>>  Char STRterm[]  = { 't', 'e', 'r', 'm', '\0' };
>>  Char STRthen[]  = { 't', 'h', 'e', 'n', '\0' };
>>  Char STRtilde[] = { '~', '\0' };
>> Index: bin/csh/csh.c
>> ===
>> RCS file: /var/cvs/src/bin/csh/csh.c,v
>> retrieving revision 1.41
>> diff -u -p -r1.41 csh.c
>> --- bin/csh/csh.c30 Aug 2017 06:42:21 -  1.41
>> +++ bin/csh/csh.c8 Dec 2017 12:16:00 -
>> @@ -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);
>> Index: bin/ksh/lex.c
>> ===
>> 

Re: Include hostname in shell prompts by default

2017-12-09 Thread x9p
On Sat, December 9, 2017 3:44 pm, Theo Buehler wrote:
> This was discussed in a smaller circle and has been in snaps for two
> days, but I'd like to show this to a wider audience.
>
> Theo asked me to make sure that all our shells print a prompt including
> the hostname by default. The reasoning is roughly as follows:
>
> 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.
>

+1 for this. some of my tmux panes + PS1 are already customized to avoid
such mistakes. but once issued "reboot" just before leaving office - sadly
it was an SSH to the BGP router, not my machine.

cheers.

x9p



Re: Include hostname in shell prompts by default

2017-12-09 Thread Theo de Raadt
> Sat, 09 Dec 2017 12:02:07 -0700 "Theo de Raadt" 
> > > With all the respect and understanding what you're saying is true, yet
> > > I have the time to change my prompt, and it would still affect me.  
> > 
> > If you have changed it, it is irrelevant what the value was before
> > the change.  You detail no impact.  You appeal is 100% emotion.
> 
> Hi Theo,
> 
> Anyone use Emacs tramp mode?  If it works after this change, I'm happy.
> If not, I'd have to go and plea there, or plea here to have a tunable..
> Over time tramp mode will pick it up, just as it picked up bash prompt.
> Please don't let me get in the way of this change, objection retracted.

OH COME ON

If you are noting the problem, then you probably use the software!

The diff is *trivial* to apply, and you could have tested that case
before you replied, then provided definitive FACTUAL INFORMATION to
the conversation instead of moaning and groaning all emo.

As I've told a few other people, this diff seperates the boys from the
men.  The boys are the ones with 1 machine, maybe 2 with seperate
keyboards.  The men are the ones with 50 machine or maybe even more,
who are struggling with the time commitment to keep infrastructure on
the leading tip, and therefore this totally minimal default prompt
setting may be a substantial step at reducing error.

But maybe this boys vs men comparison also regards other
conversational strategies, you ever think of that??

It is sub-conversations like this which cause many developers to not
send their diffs to tech and move them forward more privately.  This
forum has too many people who think their voice is equal when their
discourse is sub-equal.  A big part of the project is a meritocratic
which requires participants aim to keep the conversation about the
TECHNICAL IMPACT rather than only 'gut reaction'.  Therefore many of
you are not equal, because you don't attempt to be equal in discourse.
You are 2 for 2 of saying essentially "maybe but maybe not" and taking
no effort to elevate to FACTS.  Looking at my cat on the couch I see a
clear look of "maybe but maybe not".  I think we can expect better on
this list.



Re: Include hostname in shell prompts by default

2017-12-09 Thread Ian Darwin

On 2017-12-09 1:10 PM, Theo de Raadt wrote:

the default prompt works exactly because it doesn;t try to second guess
what the user wants, or what is or isn;t good for them. the mechanism
for changing the prompt is trivial.

i don;t think it makes sense to change the shells in this way.

Having seen bug reports with data from the wrong machine multiple
times in the last year, especially related to Mike's new work in vmm,
I'm sorry I have to disagree.  Some developers have even rebooted
the wrong machines.

Is there anyone who hasn't?


Not everyone has time to configure their development machines
as you suggest.
If it truly can't be fixed in /etc/profile and/or /etc/ksh.kshrc, then 
it should be fixed it in the code.


This change has *no impact* on the people who already take the time
to change their prompt.  It improves the lives of those who don't have
time to do so.


Yup.



Re: Include hostname in shell prompts by default

2017-12-09 Thread Job Snijders
On Sat, Dec 09, 2017 at 06:44:44PM +0100, Theo Buehler wrote:
> Theo asked me to make sure that all our shells print a prompt
> including the hostname by default.

Thank you. This is a significant improvement.

I keep finding myself updating /etc/profile everywhere to ensure I don't
lose my bearings on where I am.

Kind regards,

Job



Re: Include hostname in shell prompts by default

2017-12-09 Thread lists
Sat, 09 Dec 2017 12:02:07 -0700 "Theo de Raadt" 
> > With all the respect and understanding what you're saying is true, yet
> > I have the time to change my prompt, and it would still affect me.  
> 
> If you have changed it, it is irrelevant what the value was before
> the change.  You detail no impact.  You appeal is 100% emotion.

Hi Theo,

Anyone use Emacs tramp mode?  If it works after this change, I'm happy.
If not, I'd have to go and plea there, or plea here to have a tunable..
Over time tramp mode will pick it up, just as it picked up bash prompt.
Please don't let me get in the way of this change, objection retracted.

Kind regards,
Anton Lazarov



Re: Include hostname in shell prompts by default

2017-12-09 Thread Base Pr1me
As a server admin, I adore the idea. I've yelled profanity too many times
rebooting the wrong machine in haste. Would be wonderful in a large tmux
session.

On Dec 9, 2017 11:57,  wrote:

Sat, 09 Dec 2017 11:10:03 -0700 "Theo de Raadt" 
> > the default prompt works exactly because it doesn;t try to second guess
> > what the user wants, or what is or isn;t good for them. the mechanism
> > for changing the prompt is trivial.
> >
> > i don;t think it makes sense to change the shells in this way.
>
> Having seen bug reports with data from the wrong machine multiple
> times in the last year, especially related to Mike's new work in vmm,
> I'm sorry I have to disagree.  Some developers have even rebooted
> the wrong machines.
>
> Not everyone has time to configure their development machines
> as you suggest.
>
> This change has *no impact* on the people who already take the time
> to change their prompt.  It improves the lives of those who don't have
> time to do so.
>

Hi Theo, Theo, Jason and everyone,

With all the respect and understanding what you're saying is true, yet
I have the time to change my prompt, and it would still affect me.  By
not being able to use remote log-ins and remote file edits by software
that depends on both interactive and non interactive shell behaviours.
Please, kindly provide a snippet in skel (profile) to revert this too.

Kind regards,
Anton Lazarov


Re: Include hostname in shell prompts by default

2017-12-09 Thread Theo de Raadt
> With all the respect and understanding what you're saying is true, yet
> I have the time to change my prompt, and it would still affect me.

If you have changed it, it is irrelevant what the value was before
the change.  You detail no impact.  You appeal is 100% emotion.



Re: Include hostname in shell prompts by default

2017-12-09 Thread lists
Sat, 09 Dec 2017 11:10:03 -0700 "Theo de Raadt" 
> > the default prompt works exactly because it doesn;t try to second guess
> > what the user wants, or what is or isn;t good for them. the mechanism
> > for changing the prompt is trivial.
> > 
> > i don;t think it makes sense to change the shells in this way.  
> 
> Having seen bug reports with data from the wrong machine multiple
> times in the last year, especially related to Mike's new work in vmm,
> I'm sorry I have to disagree.  Some developers have even rebooted
> the wrong machines.
> 
> Not everyone has time to configure their development machines
> as you suggest.
> 
> This change has *no impact* on the people who already take the time
> to change their prompt.  It improves the lives of those who don't have
> time to do so.
> 

Hi Theo, Theo, Jason and everyone,

With all the respect and understanding what you're saying is true, yet
I have the time to change my prompt, and it would still affect me.  By
not being able to use remote log-ins and remote file edits by software
that depends on both interactive and non interactive shell behaviours.
Please, kindly provide a snippet in skel (profile) to revert this too.

Kind regards,
Anton Lazarov



Re: Include hostname in shell prompts by default

2017-12-09 Thread Marc Espie
On Sat, Dec 09, 2017 at 06:33:32PM +, Jason McIntyre wrote:
> On Sat, Dec 09, 2017 at 11:10:03AM -0700, Theo de Raadt wrote:
> > > the default prompt works exactly because it doesn;t try to second guess
> > > what the user wants, or what is or isn;t good for them. the mechanism
> > > for changing the prompt is trivial.
> > > 
> > > i don;t think it makes sense to change the shells in this way.
> > 
> > Having seen bug reports with data from the wrong machine multiple
> > times in the last year, especially related to Mike's new work in vmm,
> > I'm sorry I have to disagree.  Some developers have even rebooted
> > the wrong machines.
> > 
> > Not everyone has time to configure their development machines
> > as you suggest.
> > 
> > This change has *no impact* on the people who already take the time
> > to change their prompt.  It improves the lives of those who don't have
> > time to do so.
> 
> evening.
> 
> people have plenty time to change their prompt.
> 
> having the hostname in your prompt will not prevent you from rebooting
> the wrong machine (i have found).
> 
> this just feels like a needless deviation.

Not always, not under every circumstance.

Do a chroot, forget to change your prompt back -> boom, where are you.

Run vmm, forget to change your prompt.

Run lots of vm. Run lots of chroot.

Or, hey, find time to write scripts that will write environment that will
set your prompt in a nice complex fringe case.

For me, this is progress. Even if it deviates (slightly) from POSIX.



Re: Include hostname in shell prompts by default

2017-12-09 Thread Theo de Raadt
> this just feels like a needless deviation.

all i can say is:

bash-4.4$ 




Re: Include hostname in shell prompts by default

2017-12-09 Thread Jason McIntyre
On Sat, Dec 09, 2017 at 11:10:03AM -0700, Theo de Raadt wrote:
> > the default prompt works exactly because it doesn;t try to second guess
> > what the user wants, or what is or isn;t good for them. the mechanism
> > for changing the prompt is trivial.
> > 
> > i don;t think it makes sense to change the shells in this way.
> 
> Having seen bug reports with data from the wrong machine multiple
> times in the last year, especially related to Mike's new work in vmm,
> I'm sorry I have to disagree.  Some developers have even rebooted
> the wrong machines.
> 
> Not everyone has time to configure their development machines
> as you suggest.
> 
> This change has *no impact* on the people who already take the time
> to change their prompt.  It improves the lives of those who don't have
> time to do so.

evening.

people have plenty time to change their prompt.

having the hostname in your prompt will not prevent you from rebooting
the wrong machine (i have found).

this just feels like a needless deviation.

jmc



Re: Include hostname in shell prompts by default

2017-12-09 Thread Bryan Steele
On Sat, Dec 09, 2017 at 06:44:44PM +0100, Theo Buehler wrote:
> This was discussed in a smaller circle and has been in snaps for two
> days, but I'd like to show this to a wider audience.
> 
> Theo asked me to make sure that all our shells print a prompt including
> the hostname by default. The reasoning is roughly as follows:
> 
> 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.
> 
> Since not everybody makes use of the config files in /etc/skel or runs
> only login shells, it is not really possible to handle this with config
> files. Thus, we decided to hardcode it in the shells. We are aware that
> POSIX says that PS1 defaults to '$ ' or '# ' for sh(1).
> 
> The simplest case is ksh: rely on the already existing shell escapes.
> For sh we can easily fall back to these (the diff to ksh/lex.c).  For
> csh, I decided to implement the "%m" prompt escape which is standard in
> c-type shells, so I don't expect this to cause surprises.
> 
> In single user mode and the early installer, gethostname() returns the
> empty string, so the familiar prompts will be displayed there.

I think we should go ahead with this for the reasons mentioned, the
default configuration should make things easier for the people using it,
which means developers doing release builds, spinning up vms, etc.

People can go on and on about standards compliance, but if it means
someone is less likely to reboot the wrong machine, or worse, then
POSIX be damned.

ok brynet@

> Index: bin/csh/const.c
> ===
> RCS file: /var/cvs/src/bin/csh/const.c,v
> retrieving revision 1.8
> diff -u -p -r1.8 const.c
> --- bin/csh/const.c   26 Oct 2015 16:27:04 -  1.8
> +++ bin/csh/const.c   8 Dec 2017 12:15:26 -
> @@ -114,6 +114,8 @@ Char STRprintexitvalue[] = { 'p', 'r', '
>   'a', 'l', 'u', 'e', '\0' };
>  Char STRprompt[] = { 'p', 'r', 'o', 'm', 'p', 't', '\0' };
>  Char STRprompt2[]= { 'p', 'r', 'o', 'm', 'p', 't', '2', '\0' };
> +Char STRpromptroot[] = { '%', 'm', '#', ' ', '\0' };
> +Char STRpromptuser[] = { '%', 'm', '%', ' ', '\0' };
>  Char STRpushdsilent[]= { 'p', 'u', 's', 'h', 'd', 's', 'i', 'l', 
> 'e', 'n',
>   't', '\0' };
>  Char STRret[]= { '\n', '\0' };
> @@ -138,8 +140,6 @@ Char STRspor2sp[] = { ' ', '|', '|', ' '
>  Char STRsporsp[] = { ' ', '|', ' ', '\0' };
>  Char STRstar[]   = { '*', '\0' };
>  Char STRstatus[] = { 's', 't', 'a', 't', 'u', 's', '\0' };
> -Char STRsymcent[]= { '%', ' ', '\0' };
> -Char STRsymhash[]= { '#', ' ', '\0' };
>  Char STRterm[]   = { 't', 'e', 'r', 'm', '\0' };
>  Char STRthen[]   = { 't', 'h', 'e', 'n', '\0' };
>  Char STRtilde[]  = { '~', '\0' };
> Index: bin/csh/csh.c
> ===
> RCS file: /var/cvs/src/bin/csh/csh.c,v
> retrieving revision 1.41
> diff -u -p -r1.41 csh.c
> --- bin/csh/csh.c 30 Aug 2017 06:42:21 -  1.41
> +++ bin/csh/csh.c 8 Dec 2017 12:16:00 -
> @@ -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);
> Index: bin/ksh/lex.c
> ===
> RCS file: /var/cvs/src/bin/ksh/lex.c,v
> retrieving revision 1.72
> diff -u -p -r1.72 lex.c
> --- bin/ksh/lex.c 7 Dec 2017 01:54:33 -   1.72
> +++ bin/ksh/lex.c 8 Dec 2017 11:02:10 -
> @@ -1246,7 +1246,8 @@ dopprompt(const char *sp, int ntruncate,
>  

Re: Include hostname in shell prompts by default

2017-12-09 Thread Theo de Raadt
> the default prompt works exactly because it doesn;t try to second guess
> what the user wants, or what is or isn;t good for them. the mechanism
> for changing the prompt is trivial.
> 
> i don;t think it makes sense to change the shells in this way.

Having seen bug reports with data from the wrong machine multiple
times in the last year, especially related to Mike's new work in vmm,
I'm sorry I have to disagree.  Some developers have even rebooted
the wrong machines.

Not everyone has time to configure their development machines
as you suggest.

This change has *no impact* on the people who already take the time
to change their prompt.  It improves the lives of those who don't have
time to do so.



Re: Include hostname in shell prompts by default

2017-12-09 Thread Jason McIntyre
On Sat, Dec 09, 2017 at 06:44:44PM +0100, Theo Buehler wrote:
> This was discussed in a smaller circle and has been in snaps for two
> days, but I'd like to show this to a wider audience.
> 
> Theo asked me to make sure that all our shells print a prompt including
> the hostname by default. The reasoning is roughly as follows:
> 
> 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.
> 
> Since not everybody makes use of the config files in /etc/skel or runs
> only login shells, it is not really possible to handle this with config
> files. Thus, we decided to hardcode it in the shells. We are aware that
> POSIX says that PS1 defaults to '$ ' or '# ' for sh(1).
> 
> The simplest case is ksh: rely on the already existing shell escapes.
> For sh we can easily fall back to these (the diff to ksh/lex.c).  For
> csh, I decided to implement the "%m" prompt escape which is standard in
> c-type shells, so I don't expect this to cause surprises.
> 
> In single user mode and the early installer, gethostname() returns the
> empty string, so the familiar prompts will be displayed there.
> 

hi.

the default prompt works exactly because it doesn;t try to second guess
what the user wants, or what is or isn;t good for them. the mechanism
for changing the prompt is trivial.

i don;t think it makes sense to change the shells in this way.

jmc

> Index: bin/csh/const.c
> ===
> RCS file: /var/cvs/src/bin/csh/const.c,v
> retrieving revision 1.8
> diff -u -p -r1.8 const.c
> --- bin/csh/const.c   26 Oct 2015 16:27:04 -  1.8
> +++ bin/csh/const.c   8 Dec 2017 12:15:26 -
> @@ -114,6 +114,8 @@ Char STRprintexitvalue[] = { 'p', 'r', '
>   'a', 'l', 'u', 'e', '\0' };
>  Char STRprompt[] = { 'p', 'r', 'o', 'm', 'p', 't', '\0' };
>  Char STRprompt2[]= { 'p', 'r', 'o', 'm', 'p', 't', '2', '\0' };
> +Char STRpromptroot[] = { '%', 'm', '#', ' ', '\0' };
> +Char STRpromptuser[] = { '%', 'm', '%', ' ', '\0' };
>  Char STRpushdsilent[]= { 'p', 'u', 's', 'h', 'd', 's', 'i', 'l', 
> 'e', 'n',
>   't', '\0' };
>  Char STRret[]= { '\n', '\0' };
> @@ -138,8 +140,6 @@ Char STRspor2sp[] = { ' ', '|', '|', ' '
>  Char STRsporsp[] = { ' ', '|', ' ', '\0' };
>  Char STRstar[]   = { '*', '\0' };
>  Char STRstatus[] = { 's', 't', 'a', 't', 'u', 's', '\0' };
> -Char STRsymcent[]= { '%', ' ', '\0' };
> -Char STRsymhash[]= { '#', ' ', '\0' };
>  Char STRterm[]   = { 't', 'e', 'r', 'm', '\0' };
>  Char STRthen[]   = { 't', 'h', 'e', 'n', '\0' };
>  Char STRtilde[]  = { '~', '\0' };
> Index: bin/csh/csh.c
> ===
> RCS file: /var/cvs/src/bin/csh/csh.c,v
> retrieving revision 1.41
> diff -u -p -r1.41 csh.c
> --- bin/csh/csh.c 30 Aug 2017 06:42:21 -  1.41
> +++ bin/csh/csh.c 8 Dec 2017 12:16:00 -
> @@ -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);
> Index: bin/ksh/lex.c
> ===
> RCS file: /var/cvs/src/bin/ksh/lex.c,v
> retrieving revision 1.72
> diff -u -p -r1.72 lex.c
> --- bin/ksh/lex.c 7 Dec 2017 01:54:33 -   1.72
> +++ bin/ksh/lex.c 8 Dec 2017 11:02:10 -
> @@ -1246,7 +1246,8 @@ dopprompt(const char *sp, int ntruncate,
>   cp++;
>   if (!*cp)
>   break;
> - if 

Re: Include hostname in shell prompts by default

2017-12-09 Thread lists
Sat, 9 Dec 2017 18:44:44 +0100 Theo Buehler 
> This was discussed in a smaller circle and has been in snaps for two
> days, but I'd like to show this to a wider audience.
> 
> Theo asked me to make sure that all our shells print a prompt including
> the hostname by default. The reasoning is roughly as follows:
> 
> 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.
> 
> Since not everybody makes use of the config files in /etc/skel or runs
> only login shells, it is not really possible to handle this with config
> files. Thus, we decided to hardcode it in the shells. We are aware that
> POSIX says that PS1 defaults to '$ ' or '# ' for sh(1).
> 
> The simplest case is ksh: rely on the already existing shell escapes.
> For sh we can easily fall back to these (the diff to ksh/lex.c).  For
> csh, I decided to implement the "%m" prompt escape which is standard in
> c-type shells, so I don't expect this to cause surprises.

Hi,

I feel the need for this, and have always customised my PS1 everywhere.
Please, also test this to make sure Emacs tramp mode does not get to be
a show stopper, for it expects the prompt to be a certain simple form..
Maybe POSIX / something else, I'd be really really disappointed if they
refused to adjust around (any) non-standard implementations on our end.

Kind regards,
Anton Lazarov

> In single user mode and the early installer, gethostname() returns the
> empty string, so the familiar prompts will be displayed there.
> 
> Index: bin/csh/const.c
> ===
> RCS file: /var/cvs/src/bin/csh/const.c,v
> retrieving revision 1.8
> diff -u -p -r1.8 const.c
> --- bin/csh/const.c   26 Oct 2015 16:27:04 -  1.8
> +++ bin/csh/const.c   8 Dec 2017 12:15:26 -
> @@ -114,6 +114,8 @@ Char STRprintexitvalue[] = { 'p', 'r', '
>   'a', 'l', 'u', 'e', '\0' };
>  Char STRprompt[] = { 'p', 'r', 'o', 'm', 'p', 't', '\0' };
>  Char STRprompt2[]= { 'p', 'r', 'o', 'm', 'p', 't', '2', '\0' };
> +Char STRpromptroot[] = { '%', 'm', '#', ' ', '\0' };
> +Char STRpromptuser[] = { '%', 'm', '%', ' ', '\0' };
>  Char STRpushdsilent[]= { 'p', 'u', 's', 'h', 'd', 's', 'i', 'l', 
> 'e', 'n',
>   't', '\0' };
>  Char STRret[]= { '\n', '\0' };
> @@ -138,8 +140,6 @@ Char STRspor2sp[] = { ' ', '|', '|', ' '
>  Char STRsporsp[] = { ' ', '|', ' ', '\0' };
>  Char STRstar[]   = { '*', '\0' };
>  Char STRstatus[] = { 's', 't', 'a', 't', 'u', 's', '\0' };
> -Char STRsymcent[]= { '%', ' ', '\0' };
> -Char STRsymhash[]= { '#', ' ', '\0' };
>  Char STRterm[]   = { 't', 'e', 'r', 'm', '\0' };
>  Char STRthen[]   = { 't', 'h', 'e', 'n', '\0' };
>  Char STRtilde[]  = { '~', '\0' };
> Index: bin/csh/csh.c
> ===
> RCS file: /var/cvs/src/bin/csh/csh.c,v
> retrieving revision 1.41
> diff -u -p -r1.41 csh.c
> --- bin/csh/csh.c 30 Aug 2017 06:42:21 -  1.41
> +++ bin/csh/csh.c 8 Dec 2017 12:16:00 -
> @@ -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);
> Index: bin/ksh/lex.c
> ===
> RCS file: /var/cvs/src/bin/ksh/lex.c,v
> retrieving revision 1.72
> diff -u -p -r1.72 lex.c
> --- bin/ksh/lex.c 7 Dec 2017 01:54:33 -   1.72
> +++ bin/ksh/lex.c 8 Dec 2017 11:02:10 -
> @@ -1246,7 +1246,8 @@ dopprompt(const char *sp, int