[Top][All Lists]

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

Lengthy working dir (\w) breaks wrapping in a multi line coloured PS1 pr

From: Jinesh Choksi
Subject: Lengthy working dir (\w) breaks wrapping in a multi line coloured PS1 prompt
Date: Tue, 17 Dec 2013 14:59:51 +0000 (UTC)

Configuration Information [Automatically generated, do not change]:
Machine: x86_64
OS: linux-gnu
Compiler: gcc
Compilation CFLAGS:  -DPROGRAM='bash' -DCONF_HOSTTYPE='x86_64' 
-DCONF_OSTYPE='linux-gnu' -DCONF_MACHTYPE='x86_64-pc-linux-gnu' 
-DCONF_VENDOR='pc' -DLOCALEDIR='/usr/share/locale' -DPACKAGE='bash' -DSHELL 
-DHAVE_CONFIG_H   -I.  -I../bash -I../bash/include -I../bash/lib  
-D_FORTIFY_SOURCE=2 -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat 
-Werror=format-security -Wall
uname output: Linux debian 3.11-2-amd64 #1 SMP Debian 3.11.10-1 (2013-12-04) 
x86_64 GNU/Linux
Machine Type: x86_64-pc-linux-gnu

Bash Version: 4.2
Patch Level: 45
Release Status: release

The simplest PS1 prompt which demonstrates the issue is:

PS1="\[\033[01;31m\]Hello address@hidden:\[\033[01;32m\]\w\$\[\033[00m\] "

The issue is that a lengthy current working directory gets split up before the 
width of the terminal is reached.

This happens only when colour sequences are used. When no colour sequences are 
used, the prompt works correctly.

I tested this on Fedora 20 (same version of bash as above) and could reproduce 
the issue.

1. Create a long directory path for the test. E.g.

mkdir -p 

2. Ensure your terminal size is 80x24. I've tested this on linux 
console/xterm/konsole/lxterminal and PuTTY.

3. Set the PS1 prompt to:

PS1="\[\033[01;31m\]Hello address@hidden:\[\033[01;32m\]\w\$\[\033[00m\] "

Prompt should look like:

Hello world

4. Change to the long directory path:


5. Observe that the prompt is now displayed as:


The only work around I identified is to:
a) Not have any colour sequences after the \n
b) or to not have the \w after the \n

reply via email to

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