delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2007/11/14/08:55:34

X-Recipient: archive-cygwin AT delorie DOT com
X-Spam-Check-By: sourceware.org
X-Authority-Analysis: v=1.0 c=1 a=xe8BsctaAAAA:8 a=AZSAove6mhYsVPU8RkwA:9 a=3LeE127mJdR_naB02DPVkvxUBhkA:4 a=eDFNAWYWrCwA:10 a=rPt6xJ-oxjAA:10
Message-ID: <473AFE81.8030900@byu.net>
Date: Wed, 14 Nov 2007 06:56:17 -0700
From: Eric Blake <ebb9 AT byu DOT net>
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.6) Gecko/20070728 Thunderbird/2.0.0.6 Mnenhy/0.7.5.666
MIME-Version: 1.0
To: cygwin AT cygwin DOT com
Subject: Re: Workaround for silent linkage errors
References: <2D9E96311DCA4C48BF185EA6928BC7BB02BA7757 AT asc-mail DOT int DOT ascribe DOT com>
In-Reply-To: <2D9E96311DCA4C48BF185EA6928BC7BB02BA7757@asc-mail.int.ascribe.com>
X-IsSubscribed: yes
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

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

According to Phil Betts on 11/9/2007 10:15 AM:
> 
> It is designed to be installed in /etc/profile.d and uses one of
> two methods:
> 
> 1) Use $PROMPT_COMMAND

Won't work as posted, since profile.d is loaded by all bourne-style
shells, but 'declare -r' is bash-specific.  Why not propose a patch for
/etc/profile in the base-files package instead, to change the default
cygwin prompt for new installations?  And even if you want to keep this as
a profile.d script, at least do some sanity checking that you are only
installing it for bash.

> I have made 
> the variable read-only so that should a user want to override it, 
> they'd have to take extra steps and in doing so would learn why it 
> is set up that way.

Yuck - since the variable is made read-only in a profile.d script, the
only way to undo that is to edit the profile.d script.  Ouch.  At least
allow for an environment variable override, rather than requiring editing
a system file.

> 
> It's by no means a perfect solution, because the error is only
> detected if the last command executed before the prompt failed.

Have you looked into making your PROMPT_COMMAND use PIPESTATUS?  For that
matter, I avoid PROMPT_COMMAND, and get all my exit statuses at once with
this PS1:

PS1='\[\033[0m\]\n\[\033[32m\]\u@\h \[\033[35m\]'\
'(${PIPESTATUS[*]}) \[\033[33m\]\w\[\033[0m\]\n\$ '


> 
> This might be considered a better solution, as it also works inside 
> functions (if set -E is used) and sourced scripts, but it has the 
> disadvantage of printing the message twice if it was the last command 
> in the script which failed - once as the error is trapped within the 
> script, and once as the return status of the script is detected.

Ah, but you could have your trap change the return status to some other
failure value, so that the message doesn't print a second time.  But you
are right that trapping ERR is prone to be lost in user scripts.

> I've lifted the copyright message from Eric Blake's 00bash.sh script,

Fine by me, since I lifted it from somewhere else (I think it was from the
GNU Coding Standards recommendations for how to make short files maximally
reusable while still declaring copyright, unlike what 'public domain'
achieves).

- --
Don't work too hard, make some time for fun as well!

Eric Blake             ebb9 AT byu DOT net
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.5 (Cygwin)
Comment: Public key at home.comcast.net/~ericblake/eblake.gpg
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFHOv6B84KuGfSFAYARAuWqAKCkjrziKAAuW1E53WDxR2jE6W/BmgCfd8ND
6iNlLKg2nMHTVGRzOikxH00=
=JHQU
-----END PGP SIGNATURE-----

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

- Raw text -


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