delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2017/04/05/17:43:53

X-Recipient: archive-cygwin AT delorie DOT com
DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id
:list-unsubscribe:list-subscribe:list-archive:list-post
:list-help:sender:subject:references:to:from:reply-to:message-id
:date:mime-version:in-reply-to:content-type
:content-transfer-encoding; q=dns; s=default; b=kfuky1shewiKxLuS
U8KYdr8S4wMTGHRsHihuaChgjnZ2P7imcvS1H4BFo4xiAOuu1x4YP2WaOXFJQaFd
5yOAmERqM3kmhFoHb0vF+IVaF8bLL+XsneOQI54xpQfZy30gO95+Ts9gL+3nP4Fh
YckytmeyrqPo1jn9Z+RA1pH/0qk=
DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id
:list-unsubscribe:list-subscribe:list-archive:list-post
:list-help:sender:subject:references:to:from:reply-to:message-id
:date:mime-version:in-reply-to:content-type
:content-transfer-encoding; s=default; bh=ZDUMeO69aMmQMfAdETitpS
mrwLQ=; b=uUfaOevJ6tkxBCFopvrqhLYROGhI6BQWNEcl7+9P2+74Bn0RujHNmu
xSfNAwOTHknrl0RLddZ0rlm0xTN2cUabCJDqbSHlBZSBqKBSHOe5KsQIIB5JEOEa
UaJln7kcVHAWGqyws+6DhflzxZifMc9/nT1Ps41Q05sHHXF1WZ0xs=
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com
Authentication-Results: sourceware.org; auth=none
X-Virus-Found: No
X-Spam-SWARE-Status: No, score=-1.4 required=5.0 tests=AWL,BAYES_00,KAM_LAZY_DOMAIN_SECURITY,RCVD_IN_DNSWL_LOW autolearn=no version=3.3.2 spammy=reminders, raising, H*F:D*ab.ca, H*RU:64.59.134.12
X-HELO: smtp-out-no.shaw.ca
X-Authority-Analysis: v=2.2 cv=JLpLi4Cb c=1 sm=1 tr=0 a=WqCeCkldcEjBO3QZneQsCg==:117 a=WqCeCkldcEjBO3QZneQsCg==:17 a=IkcTkHD0fZMA:10 a=rkwH7_d6U9TU8iWhkloA:9 a=QEXdDO2ut3YA:10
Subject: Re: Why does default shell prompt PS1 contain newlines (\n)?
References: <1661013492 DOT 3298 DOT 1491411213549 AT communicator DOT strato DOT com> <3967f489-c760-4d91-6d9f-5b645b4b3647 AT gmail DOT com>
To: cygwin AT cygwin DOT com
From: Brian Inglis <Brian DOT Inglis AT SystematicSw DOT ab DOT ca>
Reply-To: Brian DOT Inglis AT SystematicSw DOT ab DOT ca
Message-ID: <d57e6d1f-2bb0-1ef0-ed4b-a93e3d5ba478@SystematicSw.ab.ca>
Date: Wed, 5 Apr 2017 15:43:19 -0600
User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0
MIME-Version: 1.0
In-Reply-To: <3967f489-c760-4d91-6d9f-5b645b4b3647@gmail.com>
X-CMAE-Envelope: MS4wfBFwEeFGnc5i6buxXqLZHLsMuynAlLt/kVaeAYCHyvfCA2Te29dCXJQ1hzWl5T0dgtK1SDg9ilPpjLAHdl0YL6+wOXMUI702x64u1afwgeMoGk5RopII bqJbm9lq/tedNOk1uf0qU2yWNmCpJyCUhZ6HfEdhpiBUTPbDLwQpvnqfwslfoCBDFzS6ataNilfJeQ==
X-IsSubscribed: yes

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 AT 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 AT 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 AT host \u@\h in the window 
title, whereas for other accounts, user AT 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

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019