Subject: pkg/29791: bash miscalculates non-printing characters in prompt
To: None <,,>
From: None <>
List: pkgsrc-bugs
Date: 03/25/2005 08:59:00
>Number:         29791
>Category:       pkg
>Synopsis:       bash miscalculates non-printing characters in prompt
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    pkg-manager
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Fri Mar 25 08:59:00 +0000 2005
>Originator:     Juha-Matti Liukkonen
>Release:        NetBSD 2.0
People are dolls, tired of dancing
The lamb on the altar
Where does the dream of mechanical devices go?
System: NetBSD snafu 2.0 NetBSD 2.0 (GENERIC) #0: Wed Dec 1 10:58:25 UTC 2004 builds@build:/big/builds/ab/netbsd-2-0-RELEASE/i386/200411300000Z-obj/big/builds/ab/netbsd-2-0-RELEASE/src/sys/arch/i386/compile/GENERIC i386
Architecture: i386
Machine: i386

snafu:~$ pkg_info|grep bash
bash-3.0pl16        The GNU Bourne Again Shell

Also occurs with bash-2.05.
Define a prompt with a sequence of non-printing characters, i.e. an
escape sequence to change xterm title. Observe the cursor being
positioned one character too far after PS1. Do something which
requires tab completion, and the position resets correctly.

If the \[\] is omitted, the initial position is calculated correctly,
but then line wrapping goes awry because the visible prompt length is
known incorrectly.

The PS1 sequence shown below works with the same bash versions in
darwin, freebsd, linux, ... using the same terminal (in my case,
usually mac osx's Terminal). Since the problem also occurs in netbsd
with multiple versions of bash, methinks this is probably not a bash
problem per se, but maybe a libc thing?

Observe an extra space after $ initially. Resets correctly after
the double-TAB. (The one space I _want_ there; whether the string
ends in space or not is not significant for this PR.)

snafu:~$  echo $PS[TAB][TAB]
$PS1  $PS2  $PS4
snafu:~$ echo $PS1
snafu:~$  echo "|$PS1|"
|\[\e]0;\h:\w\007\]\h:\W$ |