Bug 30634 - improvement to /etc/bashrc
Summary: improvement to /etc/bashrc
Keywords:
Status: CLOSED RAWHIDE
Alias: None
Product: Red Hat Linux
Classification: Retired
Component: bash
Version: 7.0
Hardware: i386
OS: Linux
medium
medium
Target Milestone: ---
Assignee: Bernhard Rosenkraenzer
QA Contact:
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2001-03-05 07:04 UTC by Mark Fassler
Modified: 2008-05-01 15:37 UTC (History)
1 user (show)

Fixed In Version:
Doc Type: Enhancement
Doc Text:
Clone Of:
Environment:
Last Closed: 2001-03-06 17:50:46 UTC
Embargoed:


Attachments (Terms of Use)

Description Mark Fassler 2001-03-05 07:04:57 UTC
Suggestion to improve /etc/bashrc
---------------------------------

Currently, /etc/bashrc has this:

    case $TERM in
        xterm*)
            PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME}: ${PWD\ 
007"'
            ;;
        *)
            ;;
    esac



The behavior is fine; however, I administer multiple systems and 
would like to have an easier way to modifiy the $PROMPT_COMMAND

I would like those lines to be replaced with something like this:

    case $TERM in
        xterm*)
        PROMPT_COMMAND=/usr/bin/prompt-xterm
            ;;
        *)
        PROMPT_COMMAND=/usr/bin/prompt-default
            ;;
    esac


in /usr/bin/prompt-xterm, I have this:  

echo -ne "\033]0;${USER}@${HOSTNAME}:${PWD}\007"
/usr/bin/prompt-default


in /usr/bin/prompt-default is where I have my own stuff.


Additional Info/History
-----------------------
I did this because I wanted a more intelligent mail-notification 
system.  So many times I get the message "New mail has arrived." when
it hasn't.  Sometimes I don't get notified.  Sometimes I get notified
on two different ssh sessions.

I use qmail.  What I did was this:

in my /etc/qmail/control/aliasempty file I put this:

./Maildir/
|echo `date '+%s'` >$HOME/.newmail


(When new mail arrives, qmail puts the date the mail arrived in 
$HOME/.newmail.  This has the format of seconds since 00:00:00 Jan 1,
1970.  If another message arrives, the date of the latest message
overwrites any previous values in $HOME/.newmail.)

In /usr/bin/prompt-default, I have this:

if [ -f $HOME/.newmail ]; then
        ARRIVED=`cat $HOME/.newmail`
        rm $HOME/.newmail

        AGE=$[`date '+%s'`-$ARRIVED]

        if [ $AGE -lt 0 ] ; then
                NOTIFY="New mail has arrived."
        elif [ $AGE -eq 0 ] ; then
                NOTIFY="New mail just arrived."
        else
                if [ $AGE -lt 60 ] ; then
                        QTY=$AGE
                        UNIT="second"
                elif [ $AGE -lt 3600 ]; then
                        QTY=$[($AGE+30)/60]
                        UNIT="minute"
                elif [ $AGE -lt 86400 ]; then
                        QTY=$[($AGE+1800)/3600]
                        UNIT="hour"
                else
                        QTY=$[($AGE+43200)/86400]
                        UNIT="day"
                fi

                if [ $QTY -ne 1 ]; then
                        UNIT="$UNIT"s
                fi

                NOTIFY="New mail arrived $QTY $UNIT ago."
        fi

        echo
        echo " * $NOTIFY"
        echo

fi

(Every time I press return in an interactive bash shell, the system
does a quick check to see if $HOME/.newmail has arrived.  If so, it
calculates how long ago it arrived and formats it into a nice, user-
friendly format like this:

 * New mail arrived 7 minutes ago

I receive this message only once, on only one terminal, and it is
always a true statement.)

I have my email client renamed (mutt --> mutt-binary) and run from a 
script (mutt).  In the mutt script, after the binary has exited, it 
deletes $HOME/.newmail so that I don't hear about email received while
I was reading mail.  

I'm not proposing that everyone adopt my email notification system (it
is very nice, though).  I just want a generic way for everyone to be
able to implement their own $PROMPT_COMMAND enhancements.

Comment 1 Bernhard Rosenkraenzer 2001-03-05 16:57:30 UTC
The problem with this is that it increases the overhead for every command by 
starting another shell etc.
It makes slow machines a real pain.

Comment 2 Bernhard Rosenkraenzer 2001-04-24 12:36:20 UTC
I've added something similar as an option in 2.05-1:

If /etc/sysconfig/bash-prompt-xterm exists, it is used instead of setting the 
default prompt in an xterm; in other terminals, 
/etc/sysconfig/bash-prompt-default is used.
If they don't exist (and they aren't included in the package), everything 
remains the way it was, saving overhead.



Note You need to log in before you can comment on or make changes to this bug.