public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
* Why does default shell prompt PS1 contain newlines (\n)?
@ 2017-04-05 16:53 "\"[[\"Dr. Matthias H. Fröhlich"
  2017-04-05 17:29 ` cyg Simple
  0 siblings, 1 reply; 3+ messages in thread
From: "\"[[\"Dr. Matthias H. Fröhlich" @ 2017-04-05 16:53 UTC (permalink / raw)
  To: cygwin

After installing "plain vanilla" cygwin I noticed, that default definition of PS1 from /etc/bash.bashrc contains newline characters '\n':
     # Set a default prompt of: user@host and current_directory
     PS1='\[\e]0;\w\a\]\n\[\e[32m\]\u@\h \[\e[33m\]\w\[\e[0m\]\n\$ '

This does immediately lead to the strange effect, that shell (bash) in interactive terminal window (C:\cygwin64\bin\mintty.exe -i /Cygwin-Terminal.ico -) always advances 2 lines on every single CR.

This definition seems to be around pretty long already, as it is mentioned in several discussions on superuser &c. There is probably a very good reason for this - however, I could not figure out on my own, neither found any rationale in FAQ. Would be grateful for short explanation - thanks in advance.

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Why does default shell prompt PS1 contain newlines (\n)?
  2017-04-05 16:53 Why does default shell prompt PS1 contain newlines (\n)? "\"[[\"Dr. Matthias H. Fröhlich"
@ 2017-04-05 17:29 ` cyg Simple
  2017-04-05 21:43   ` Brian Inglis
  0 siblings, 1 reply; 3+ messages in thread
From: cyg Simple @ 2017-04-05 17:29 UTC (permalink / raw)
  To: cygwin



On 4/5/2017 12:53 PM, "\"[[\"Dr. Matthias H. Fröhlich" wrote:
> After installing "plain vanilla" cygwin I noticed, that default definition of PS1 from /etc/bash.bashrc contains newline characters '\n':
>      # Set a default prompt of: user@host and current_directory
>      PS1='\[\e]0;\w\a\]\n\[\e[32m\]\u@\h \[\e[33m\]\w\[\e[0m\]\n\$ '
> 
> This does immediately lead to the strange effect, that shell (bash) in interactive terminal window (C:\cygwin64\bin\mintty.exe -i /Cygwin-Terminal.ico -) always advances 2 lines on every single CR.
> 

It's not strange at all.  You get an empty line, followed by a line
containing "USER@HOSTNAME WORKING-DIRECTORY" and finally followed by a
line containing the "$ ".

The empty line helps to identify the prompt text from text that may
appear on the terminal from commands.  Part of the string also modifies
the Window title with the current working directory.  Part of the string
controls the color of the prompt text.

> This definition seems to be around pretty long already, as it is mentioned in several discussions on superuser &c. There is probably a very good reason for this - however, I could not figure out on my own, neither found any rationale in FAQ. Would be grateful for short explanation - thanks in advance.

Since early days when version 1.0 was released or before.

You can change it in your local ~/.profile file and/or other startup
resource files.

-- 
cyg Simple

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Why does default shell prompt PS1 contain newlines (\n)?
  2017-04-05 17:29 ` cyg Simple
@ 2017-04-05 21:43   ` Brian Inglis
  0 siblings, 0 replies; 3+ messages in thread
From: Brian Inglis @ 2017-04-05 21:43 UTC (permalink / raw)
  To: cygwin

On 2017-04-05 11:28, cyg Simple wrote:
> On 4/5/2017 12:53 PM, "\"[[\"Dr. Matthias H. Fröhlich" wrote:
>> After installing "plain vanilla" cygwin I noticed, that default
>> definition of PS1 from /etc/bash.bashrc contains newline characters
>> '\n':
>>      # Set a default prompt of: user@host and current_directory
>>      PS1='\[\e]0;\w\a\]\n\[\e[32m\]\u@\h \[\e[33m\]\w\[\e[0m\]\n\$ '
>> This does immediately lead to the strange effect, that shell (bash)
>> in interactive terminal window (C:\cygwin64\bin\mintty.exe -i
>> /Cygwin-Terminal.ico -) always advances 2 lines on every single
>> CR.
> It's not strange at all.  You get an empty line, followed by a line
> containing "USER@HOSTNAME WORKING-DIRECTORY" and finally followed by a
> line containing the "$ ".
> The empty line helps to identify the prompt text from text that may
> appear on the terminal from commands.  Part of the string also modifies
> the Window title with the current working directory.  Part of the string
> controls the color of the prompt text.
>> This definition seems to be around pretty long already, as it is
>> mentioned in several discussions on superuser &c. There is probably
>> a very good reason for this - however, I could not figure out on my
>> own, neither found any rationale in FAQ. Would be grateful for
>> short explanation - thanks in advance.
> Since early days when version 1.0 was released or before.
> You can change it in your local ~/.profile file and/or other startup
> resource files.

The embedded newlines allow for when there is no \n at the end of output, 
long chroot and working directory paths, user and host names, history 
numbers, and any other info you care to cram into your primary prompt, 
leaving maximum space for the input line without wraps or eol continuation.

I cram a bit, but only use \w working directory full path in the window 
title and use \W working directory basename in the prompt, which still 
sometimes shortens your available input space on the command line by 20 
chars or so, but eol \\\n and \n in quoted strings keep longer input 
more readable.

Similarly, if you access multiple hosts, for personal accounts host names 
\h are useful reminders in the prompt, with user@host \u@\h in the window 
title, whereas for other accounts, user@host is a useful reminder in the 
prompt as well as in the window title.

Many of us will have had the experience of typing rm *dumdedum* only to 
see "No such file or directory" because of typing the command in the wrong 
terminal window, which the title and prompt attempt to alert you to.

This is a particular problem in Windows when it decides to change focus to 
some other window while you are typing, and raising the focus window lags 
the focus change: developers should raise the window before changing focus, 
to give you some warning.

-- 
Take care. Thanks, Brian Inglis, Calgary, Alberta, Canada

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2017-04-05 21:43 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-04-05 16:53 Why does default shell prompt PS1 contain newlines (\n)? "\"[[\"Dr. Matthias H. Fröhlich"
2017-04-05 17:29 ` cyg Simple
2017-04-05 21:43   ` Brian Inglis

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).