bug-bash
[Top][All Lists]
Advanced

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

PS1 prompt problem


From: Nils
Subject: PS1 prompt problem
Date: Fri, 16 Oct 2009 08:05:31 -0700 (PDT)
User-agent: G2/1.0

I'm using bash 3.2 and I'd like to set my prompt to the following
(inspired by the Opensolaris prompt for ksh93):

PS1='$(
    spwd="${PWD/#${HOME}/~}"
    [[ ${#spwd} -gt 10 ]] && spwd="...${spwd: -10}"
    printf "%s@%s:%s%s " "\u" "\h" "${spwd}" "\$"
    termtitle="\u@\h:${spwd}"

    ####
    printf "%s" "\["
    case "${TERM}" in
        (xterm*)
            printf "\033]0;%s\a" "${termtitle}"
            ;;
        (screen*)
            printf "\033_%s\033\\" "${termtitle}"
            ;;
    esac
    printf "%s" "\]"
    ####
)'

Basically this is supposed to shorten PWD to the last 10 characters
and set the terminal title as well. Unfortunately it causes bash to
hang, the problem seems to lie in the escape codes for entering and
leaving the terminal title and the surrounding "\[" "\]" because
commenting out the case statement and the surrounding printfs makes it
at least set the prompt correctly. I have the strong suspicion it
might be some quoting issue.

Using printf "\033]0;%s\a" "${PWD}" on the command line will set the
xterm title to $PWD.
Setting PROMPT_COMMAND='printf "\033]0;%s\a" "${PWD}"' works as well,
however I do not want to use $PROMPT_COMMAND for efficiency reasons as
I would have to calculate $spwd (and possibly other things later)
twice.
Following a suggestion in comp.unix.shell putting the above code
contained in $() inside a separate function f and setting PS1='$( f )'
displays the $spwd correctly in both the prompt and xterm title, but
bash escapes like "\u", "\h" etc are not expanded any more

What's wrong here?


reply via email to

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