smilebomb
smilebomb

Reputation: 5483

Changing my PROMPT_COMMAND adds a new line

I've added the following line to my ~/.bashrc file to change my tab title:

export PROMPT_COMMAND='echo -e "\033];My Machine\007"'

After I source the file, my prompt adds a new, blank line after every command. For example:

user machine ~:> pwd
/a/path/whatever

user machine ~:>

I don't want that third, blank line to be there. I've tested sourcing my .bashrc with and without the PROMPT_COMMAND line and I know this is the offending line. Any ideas?

Upvotes: 0

Views: 1490

Answers (2)

Benjamin W.
Benjamin W.

Reputation: 52122

The band-aid fix is to use echo -en if your echo supports that (suppress the newline).

I don't think it is necessary to use PROMPT_COMMAND here, you can just prepend it to your PS1:

PS1="\[\033]0;My Machine\007\007\]$PS1"

The \[ \] make sure that the width of what's between them doesn't throw off the line length count.

There are predefined escape sequences so you don't have to hard code the machine name, see the manual. For example this

PS1="\[\e]0;\u@\h: \w\a\]$PS1"

uses \e and \a instead of \033\ and \007 for escape and bell, and sets the tab title to user@hostname: currentdir.

See also the relevant section in the Bash Prompt HOWTO and the Xterm title HOWTO.

Upvotes: 1

RaviTezu
RaviTezu

Reputation: 3125

Try this:

export PROMPT_COMMAND='echo -en "\033];My Machine\007"'

Upvotes: 1

Related Questions