.bashrc file adds a couple of tens of spaces to the prompt

1

I got myself a .bashrc file off the net. I checked it beforehand, didn't detect anything bad about it.

One thing that's odd about it, is that several spaces are added to the terminal command line.

Screenshot:

alt text Those spaces are not put there by me.

The file can be found here: http://tldp.org/LDP/abs/html/sample-bashrc.html

KdgDev

Posted 2010-09-03T07:23:15.380

Reputation: 4 708

well, show us your $PROMPT – akira – 2010-09-03T07:57:53.350

@akira: unbound variable – KdgDev – 2010-09-03T18:13:41.363

Answers

1

When the prompt contains non-printing characters, they must be surrounded by \[…\]. Otherwise bash counts these characters as part of the width of the prompt.

The prompt settings are missing several instances of \[…\]. Here are the ones I've found after a cursory glance:

function fastprompt()
{
    unset PROMPT_COMMAND
    case $TERM in
        *term | rxvt )
            PS1="\[${HILIT}\][\h]\[$NC\] \W > \[\033]0;\${TERM} [\u@\h] \w\007\]" ;;
        linux )
            PS1="\[${HILIT}\][\h]\[$NC\] \W > " ;;
        *)
            PS1="[\h] \W > " ;;
    esac
}

function powerprompt()
{

    PROMPT_COMMAND=_powerprompt
    case $TERM in
        *term | rxvt  )
            PS1="\[${HILIT}\][\A - \$LOAD]\[$NC\]\n[\u@\h \#] \W > \
                 \[\033]0;\${TERM} [\u@\h] \w\007\]" ;;
        linux )
            PS1="\[${HILIT}\][\A - \$LOAD]\[$NC\]\n[\u@\h \#] \W > " ;;
        * )
            PS1="[\A - \$LOAD]\n[\u@\h \#] \W > " ;;
    esac
}

Gilles 'SO- stop being evil'

Posted 2010-09-03T07:23:15.380

Reputation: 58 319

2

Take a look at the function powerprompt.

If you have copied and pasted it into your .bashrc, you may have gotten spaces at the beginning of the lines ending with \ (backslash).

(Can you post your real .bashrc somewhere instead)? Or try: echo \"$PS1\"

(EDIT: Of course I mean "at the beginning of the lines following the lines ending with \.)

MattBianco

Posted 2010-09-03T07:23:15.380

Reputation: 1 763

1

Try taking out the code that is in the

#-------------------------------------------------------------
# Shell Prompt
#-------------------------------------------------------------

section of the .bashrc file. This looks to be the area that controls the appearance of the prompt.

What does your prompt look like now? If you don't notice a change, make sure you start a new Terminal window.

Beyond the .bashrc file in your home directory, there are system-wide configurations in the /etc/ folder. They are usually found in /etc/bashrc or /etc/bash_profile (note they are not hidden, no prepended .) depending on the flavour of Linux your are using.

Also - do you have any other .bash_profile or .profile like files in your home directory which might also be acting to configure the prompt?

dtlussier

Posted 2010-09-03T07:23:15.380

Reputation: 1 985