Page 1 of 1

[Solved] Bash doesn't wrap command lines with certern TERMs

Posted: 12 Mar 2012, 15:10
by dafan
If a command line is longer than the width of the terminal screen, bash should wrap the command and let the user input in the next line. It is also what bash does if the TERM environment variable is xterm.

But if TERM is set to xterm-256color, bash will not be able to wrap long command lines. It will shift the command left in the current line, copy the shifted current line to the next line and let the user input in the next line.

In GNU screen or tmux (in which TERM should be set to screen or screen-256color), bash shifts the command left in the current line and let the user input in the same line.

I also use openSUSE and bash wraps the command to the next line in the situation above.

Porteus version: Porteus-v1.1-i486 without any changes or modules

Re: Bash doesn't wrap long command lines with certern TERMs

Posted: 12 Mar 2012, 17:38
by fanthom
hello dafan,

looks like a 'PS1=' variable issue. please change this variable as follows
for /etc/profile:

Code: Select all

PS1="\[\e[1;31m\]\u@\h:\[\e[1;32m\]\w\$ \[\e[0m\]"
for /home/guest/.bashrc:

Code: Select all

PS1='\[\e[1;36m\]\u@\h:\[\e[1;32m\]\w\$ \[\e[0m\]"
and for /root/.bashrc (can't remember if it's set up here - if you wont find it then just skip):

Code: Select all

PS1="\[\e[1;31m\]\u@\h:\[\e[1;32m\]\w\$ \[\e[0m\]"
let me know if that resolves wrapping issue (i'm at work now so can't check myself).

Re: Bash doesn't wrap long command lines with certern TERMs

Posted: 12 Mar 2012, 20:02
by dafan
Hello fanthom

It doesn't seem to be a PS1 issue. It is the same if I set PS1 to what you wrote. It is the same even if I simply set PS1 to '$'.

Re: Bash doesn't wrap long command lines with certern TERMs

Posted: 13 Mar 2012, 21:44
by fanthom
bad news - i have tried Kongoni and Salix Live (both based on Slackware-13.37) and the issue persist: wrapping stops working once you switch to 256 color terminal.
looks like an upstream Slackware bug.

This Thursday i'll try to update xterm package and see if that helps.

Re: Bash doesn't wrap long command lines with certern TERMs

Posted: 14 Mar 2012, 07:16
by dafan
Thanks

btw. I am still using the old Porteus-v09 and the problem was already there.

Re: Bash doesn't wrap long command lines with certern TERMs

Posted: 16 Mar 2012, 08:32
by fanthom
@dafan

yep - i have checked slax-6.1.2 and same issue there.
i have read in few places that changing TERM variable is generally not a good idea:
click
click
click
maybe that's why it's not allowed in Slackware? but why other distros (gentoo, ubuntu, opensuse) accepts this variable?
unfortunately i dont know the answer.

other idea: maybe you could enable 256 color support as per application? please check out this source:
http://www.robmeerman.co.uk/unix/256colours

Re: Bash doesn't wrap long command lines with certern TERMs

Posted: 16 Mar 2012, 09:33
by dafan
The 256 color is not the main problem. The problem is that bash will not wrap lines if TERM is set to "screen" which must be done in GNU screen or tmux.

If TERM is set to xterm in tmux or GNU screen, some ncurses software will not be drawed properly. You can download tmux and libevent from http://tmux.sourceforge.net and http://libevent.org, compile, install them and run tmux, then set TERM to xterm and run make menuconfig in the linux kernel source tree. You will understand what I mean. (Sorry. I can not upload a picture, so you must do it yourself :unknown: )

So the problem is: For the people who use tmux or GNU screen, either the ncurses software is drawed improperly or bash will not wrap long command lines.

Re: Bash doesn't wrap long command lines with certern TERMs

Posted: 16 Mar 2012, 11:18
by fanthom
i'm able to recreate the issue with tmux but screen is working just fine for me (tested also in v09)
in case of switching to root from normal user account i had to use 'su -p' when inside screen session.

screen is the only solution for now i'm afraid.

Re: Bash doesn't wrap long command lines with certern TERMs

Posted: 16 Mar 2012, 12:42
by dafan
Really? Are you sure that you have set TERM to xterm in screen?

In my Porteus-v09 the background can not be drawed in screen if TERM is xterm. There was no .screenrc file as I tested.

Btw. the ncurses Problem also appers in my openSUSE mashine, both in screen and in tmux.

Re: Bash doesn't wrap long command lines with certern TERMs

Posted: 16 Mar 2012, 14:02
by fanthom
@dafan

i was working on default "TERM=screen" inside screen session and everything was ok: wrapping and ncurses applications.

Re: Bash doesn't wrap long command lines with certern TERMs

Posted: 16 Mar 2012, 14:59
by bigbass
give this a try

this will show what is set

Code: Select all

shopt
this is the command syntax to edit values
shopt -s optionNameHere

we want to set this for the line wrapping

Code: Select all

shopt -s  checkwinsize
and if you want to unset something like this

Code: Select all

shopt -u  checkwinsize
now to make changes stick add them to /root/.bashrc
like this
# Setup color scheme <brokenman> for list call
alias ll='/bin/ls --color=auto -lF'
alias la='/bin/ls --color=auto -axF'
alias ls='/bin/ls --color=auto -xF'

# Append any additional sh scripts found in /etc/profile.d/:
for y in /etc/profile.d/*.sh ; do [ -x $y ] && . $y; done
unset y

# Setup shell prompt for root <wread and fanthom>
PS1='\[\033[01;31m\]\u@\h:\[\033[01;32m\]\w\$\[\033[00m\] '
PS2='> '
shopt -s checkwinsize





now run

Code: Select all

shopt
to see the changes






how about a little fun ?


add this to /root/.bashrc

Code: Select all


function xtitle()      # Adds some text in the terminal frame.
{
    case "$TERM" in
        *term | rxvt)
            echo -n -e "\033]0;$*\007" ;;
        *)  
            ;;
    esac
}
xtitle= xtitle `cat /etc/porteus-version`




let me know if that helped
Joe

Re: Bash doesn't wrap long command lines with certern TERMs

Posted: 18 Mar 2012, 14:04
by dafan
@fanthom
You are right. Bash in screen doesn't wrap lines only if TERM is screen-256color. If TERM is screen, everything is OK.

@bigbass
The problem has nothing to do with bash, but thanks anyway.


Finally, I am glad to say that I have found the solution! :beer: It is because of file /etc/termcap. It only defines the termcap for xterm, but not for xterm-256color, screen or screen-256color. If I add these terminal types to the xterm termcaps (see the patch below), everything will be OK. Actually only the "up" capability is needed for bash to wrap lines (It means "cursor up one line". I'm not quite familiar with termcap and can't understand why "up one line", not "down one line".)

The termcap file in my openSUSE mashine has defined xterm-256color, screen and screen-256color, but I have found that bash still wraps lines if I delete the termcap file. So I guess the default terminfo of xterm* and screen* (they are from the ncurses library) have defined the "up" capability. Maybe updating the ncurses library will solve the problem without patching the termcap file.

Btw. I am a little bit confused with the version of the ncurses library on my openSUSE machine. The name of the .so file is /lib/libncurses{,w}.so.6.0, but the newest version of the ncurses library is 5.9.


Code: Select all

$ diff -dupN termcap.orig termcap
--- termcap.orig        2012-03-18 14:36:56.524000008 +0100
+++ termcap     2012-03-18 14:38:13.746000009 +0100
@@ -141,7 +141,7 @@ mc|minicom|ansi-mc|termcap entry for min
        :tc=linux:

 # Entry for an xterm. Insert mode has been disabled.
-vs|xterm|xterm-color|vs100|xterm terminal emulator (X Window System):\
+vs|xterm|xterm-256color|xterm-color|screen|screen-256color|vs100|xterm terminal emulator (X Window System):\
        :am:bs:mi@:km:co#80:li#55:\
        :im@:ei@:\
        :ct=\E[3k:ue=\E[m:\

Re: [Solved] Bash doesn't wrap command lines with certern TE

Posted: 18 Mar 2012, 21:42
by fanthom
well done dafan :)

i'll push your patch to rc2 of Porteus-1.2 - thanks.