bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: "su -m" (on Mac) preserves $HOME and $USER but not ~


From: Dabrien 'Dabe' Murphy
Subject: Re: "su -m" (on Mac) preserves $HOME and $USER but not ~
Date: Thu, 29 Oct 2015 19:05:33 -0400
User-agent: Postbox 3.0.11 (Macintosh/20140602)

On 10/29/15, 4:00 PM, Greg Wooledge wrote:
Do you have a PROMPT_COMMAND variable? Or something unusual in your PS1 variable? (Doesn't look it from the copy/paste, but you never know.) Or do you have a DEBUG trap?

Oh yeah, I definitely make extensive use of the PROMPT_COMMAND; that's how I stick the `date` in there.  [See below...]

I can see how that could result in, shall we say, "asynchronous" activity, but it's still a little astonishing that it would update '~' — especially without updating $HOME at the same time.

PS: This was cobbled together a long time ago, so try not to laugh TOO hard at the mix of old-school "/bin/sh"-isms... ;-)
# (grep -c)
function gc {
    local line arg="$1" counter=0
    while read line; do
        [ "$line" != "${line##*$arg}" ] && counter=$(($counter+1))
    done
    echo $counter
}

export WHOAMI="`whoami`"

export TTY="`tty 2>/dev/null`"
if [ ! "$TTY" = "" ]; then
    export TTY_OWNER="`ls -Ll \"$TTY\" 2>/dev/null | awk '{print \$3}'`"
fij

if [ "$PS1" != "" ]; then
    PROMPT_COMMAND='set_prompt'

    function set_prompt () {
        local numjobs=`jobs | gc Stopped`
        if [ "$numjobs" = 0 ]; then
            unset JOBFLAG
        else
            JOBFLAG="{$numjobs} "
        fi

        if [ "$WHOAMI" = root ]; then
            prompt="# "
            other=" (#)"
            color="^[[31;1m"
        else
            prompt="> "
            if [ ! "$WHOAMI" = "$TTY_OWNER" ]; then
                other=" ($WHOAMI)"
                color="^[[36;1m"
            else
                other=""
                color="^[[0;1m"
            fi
        fi

    PS1=
    [ ! "$STY" = "" ] && PS1="[$STY] "

    # ^[]1 = iTerm.app "tab"
    # ^[]2 = konsole "tab" and taskbar app name
    # ^[]30 = I forget...

    if [ ! "${TERM##xterm}" = "$TERM" ] || [ ! "${TERM##screen}" = "$TERM" ]; then
        local datestr=$(date +"%a %b %d %T")
        local standout_on=$(tput smso)
        local standout_off=$(tput rmso)

        PS1="\[^[]2;address@hidden \W^G^[]1;\h$other^G^[]30;\h$other^G$color$standout_on\]$datestr\[$standout_off\] address@hidden:\w${prompt}\[^[[0m\]"
    else
        PS1="\[$color$standout_on\]$datestr\[$standout_off\] address@hidden:\w${prompt}\[^[[0m\]"
    fi

    echo -n $(tput cup $(tput lines) 0)
}

fi

--
:- Dabe


reply via email to

[Prev in Thread] Current Thread [Next in Thread]