0

I am facing an issue during the usage of up and down on gnome-terminal. Lets say my previous commands are

vi pos_of_rightmost_setbit.cpp 
gcc -o harsha pos_of_rightmost_setbit.cpp

At this point when I press a up arrow,I see last previous command gcc -o harsha pos_of_rightmost_setbit.cpp which is perfect.

But when I hit up arrow again,I have to see last but one previous command which is vi pos_of_rightmost_setbit.cpp, Instead I am seeing gcc -o harvightmost_setbit.cpp.

When I hit enter at this point of time,The command vi pos_of_rightmost_setbit.cpp is working fine,So I think there some problems with bashrc settings.

I am attaching screenshots for better understanding. For previous command

For last but one previous command

starkk92
  • 5,754
  • 9
  • 43
  • 59
  • 1
    run `history` to see the cmd list you've executed. – Kent Sep 01 '14 at 12:55
  • This sounds like a terminal type or prompt setting problem causing redraw issues. Does hitting `ctrl-l` after hitting `up` cause the right command to display correctly? – Etan Reisner Sep 01 '14 at 13:06
  • @EtanReisner Yes ctrl-l after hitting up is displaying the command properly..What might be the issue? – starkk92 Sep 02 '14 at 06:37
  • @Kent Yeah! history is working fine. In fact the command which is getting displayed wrongly is also working..The only problem I see is display. – starkk92 Sep 02 '14 at 06:39
  • What is your prompt (`$PS1`) set to? What is `$TERM` set to? – Etan Reisner Sep 02 '14 at 10:00
  • @EtanReisner PS1="\e[1;39m[\u@\h \W]\$ \e[m" I have seen this issue after adding this.I have seen the behavior after commenting this.It looks fine then.What might be the issue?Thanks. – starkk92 Sep 02 '14 at 11:10

1 Answers1

1

That prompt string is exactly the problem.

You need to surround every non-printing bit of that prompt string with \[ and \] to tell readline not to count them in the length of the prompt.

So you should have something like PS1="\[\e[1;39m\][\u@\h \W]\$ \[\e[m\]".

Ref: https://superuser.com/questions/301353/escape-non-printing-characters-in-a-function-for-a-bash-prompt/301355#301355

Community
  • 1
  • 1
Etan Reisner
  • 77,877
  • 8
  • 106
  • 148